Exemple #1
0
        /// <summary>
        /// Transforms the given coordinates to the coordinate system this rectangle is defined in.
        /// </summary>
        /// <param name="width">The width of the rectangle in the coordinate system of the given coordinates.</param>
        /// <param name="height">The height of the rectangle in the coordinate system of the given coordinates.</param>
        /// <param name="reverseX">Assumes that the origin of the x-axis is on the top of this rectangle if false.</param>
        /// <param name="reverseY">Assumes that the origin of the y-axis is on the right of this rectangle if false.</param>
        /// <param name="x">The x-coordinates to transform.</param>
        /// <param name="y">The y-coordinates to transform.</param>
        public double[] TransformFrom(double width, double height, bool reverseX, bool reverseY,
                                      double x, double y)
        {
            PointF2D  reference = _bottomLeft;
            VectorF2D vectorX   = _vectorX;
            VectorF2D vectorY   = _vectorY;

            if (reverseX && !reverseY)
            {
                reference = this.BottomRight;
                vectorX   = _vectorX * -1;
            }
            else if (!reverseX && reverseY)
            {
                reference = this.TopLeft;
                vectorY   = _vectorY * -1;
            }
            else if (reverseX && reverseY)
            {
                reference = this.TopRight;
                vectorX   = _vectorX * -1;
                vectorY   = _vectorY * -1;
            }

            double widthFactor  = x / width;
            double heightFactor = y / height;

            PointF2D result = reference +
                              (vectorX * widthFactor) +
                              (vectorY * heightFactor);

            return(result.ToArray());
        }
Exemple #2
0
        public double[][] TransformFrom(double width, double height, bool reverseX, bool reverseY, double[] x, double[] y)
        {
            PointF2D  pointF2D1  = this._bottomLeft;
            VectorF2D vectorF2D1 = this._vectorX;
            VectorF2D vectorF2D2 = this._vectorY;

            if (reverseX && !reverseY)
            {
                pointF2D1  = this.BottomRight;
                vectorF2D1 = this._vectorX * -1.0;
            }
            else if (!reverseX & reverseY)
            {
                pointF2D1  = this.TopLeft;
                vectorF2D2 = this._vectorY * -1.0;
            }
            else if (reverseX & reverseY)
            {
                pointF2D1  = this.TopRight;
                vectorF2D1 = this._vectorX * -1.0;
                vectorF2D2 = this._vectorY * -1.0;
            }
            double[][] numArray = new double[x.Length][];
            for (int index = 0; index < x.Length; ++index)
            {
                double   num1      = x[index] / width;
                double   num2      = y[index] / height;
                PointF2D pointF2D2 = pointF2D1 + vectorF2D1 * num1 + vectorF2D2 * num2;
                numArray[index] = pointF2D2.ToArray();
            }
            return(numArray);
        }
Exemple #3
0
        /// <summary>
        /// Transforms the given coordinates to the coordinate system this rectangle is defined in.
        /// </summary>
        /// <param name="width">The width of the rectangle in the coordinate system of the given coordinates.</param>
        /// <param name="height">The height of the rectangle in the coordinate system of the given coordinates.</param>
        /// <param name="reverseX">Assumes that the origin of the x-axis is on the top of this rectangle if false.</param>
        /// <param name="reverseY">Assumes that the origin of the y-axis is on the right of this rectangle if false.</param>
        /// <param name="x">The x-coordinates to transform.</param>
        /// <param name="y">The y-coordinates to transform.</param>
        public double[][] TransformFrom(double width, double height, bool reverseX, bool reverseY,
                                        double[] x, double[] y)
        {
            PointF2D  reference = _bottomLeft;
            VectorF2D vectorX   = _vectorX;
            VectorF2D vectorY   = _vectorY;

            if (reverseX && !reverseY)
            {
                reference = this.BottomRight;
                vectorX   = _vectorX * -1;
            }
            else if (!reverseX && reverseY)
            {
                reference = this.TopLeft;
                vectorY   = _vectorY * -1;
            }
            else if (reverseX && reverseY)
            {
                reference = this.TopRight;
                vectorX   = _vectorX * -1;
                vectorY   = _vectorY * -1;
            }

            double[][] transformed = new double[x.Length][];
            for (int idx = 0; idx < x.Length; idx++)
            {
                double widthFactor  = x[idx] / width;
                double heightFactor = y[idx] / height;

                PointF2D result = reference +
                                  (vectorX * widthFactor) +
                                  (vectorY * heightFactor);
                transformed[idx] = result.ToArray();
            }
            return(transformed);
        }