Example #1
0
 void pBoundingBox(GeoLibPointF[] incomingPoints)
 {
     points = new List<GeoLibPointF>();
     if ((incomingPoints == null) || (incomingPoints.Length == 0))
     {
         minX = 0;
         maxX = 0;
         minY = 0;
         maxY = 0;
         points.Add(new GeoLibPointF(0.0f, 0.0f));
         points.Add(new GeoLibPointF(0.0f, 0.0f));
         points.Add(new GeoLibPointF(0.0f, 0.0f));
         points.Add(new GeoLibPointF(0.0f, 0.0f));
         midPoint = new GeoLibPointF(0.0f, 0.0f);
     }
     else
     {
         // Compile a list of our points.
         List<GeoLibPointF> iPoints = new List<GeoLibPointF>();
         for (int i = 0; i < incomingPoints.Count(); i++)
         {
             iPoints.Add(incomingPoints[i]);
         }
         minX = iPoints.Min(p => p.X);
         minY = iPoints.Min(p => p.Y);
         maxX = iPoints.Max(p => p.X);
         maxY = iPoints.Max(p => p.Y);
         points.Add(new GeoLibPointF(minX, minY));
         points.Add(new GeoLibPointF(minX, maxY));
         points.Add(new GeoLibPointF(maxX, maxY));
         points.Add(new GeoLibPointF(maxX, minY));
         midPoint = new GeoLibPointF(minX + ((maxX - minX) / 2.0f), minY + ((maxY - minY) / 2.0f));
     }
 }
 private void setOtherProps()
 {
     Left     = X;
     Top      = Y;
     Location = new GeoLibPointF(X, Y);
     Bottom   = Top + Height;
     Right    = Left + Width;
 }
Example #3
0
    private void write3Delta(GeoLibPointF p)
    {
        int w;

        switch (p.X)
        {
        case 0 when p.Y > 0:
            w = ((int)p.Y << 3) + 1;
            break;

        case 0:
            w = ((int)-p.Y << 3) + 3;
            break;

        default:
        {
            switch (p.Y)
            {
            case 0 when p.X > 0:
                w = ((int)p.X << 3) + 0;
                break;

            case 0:
                w = ((int)-p.X << 3) + 2;
                break;

            default:
            {
                switch (Math.Abs(p.Y - p.X))
                {
                case <= double.Epsilon when p.Y > 0:
                    w = ((int)p.Y << 3) + 4;
                    break;

                case <= double.Epsilon:
                    w = ((int)-p.Y << 3) + 6;
                    break;

                default:
                {
                    w = p.X switch
                    {
                        > 0 => ((int)p.X << 3) + 7,
                        _ => ((int)-p.X << 3) + 5
                    };

                    break;
                }
                }

                break;
            }
            }

            break;
        }
Example #4
0
    private void write2Delta(GeoLibPointF p)
    {
        int w = p.X switch
        {
            0 when p.Y > 0 => ((int)p.Y << 2) + 1,
            0 => ((int)-p.Y << 2) + 3,
            > 0 => ((int)p.X << 2) + 0,
            _ => ((int)-p.X << 2) + 2
        };

        writeUnsignedInteger((uint)w);
    }
Example #5
0
    private static GeoLibPointF[] pMove(GeoLibPointF[] source, double x, double y)
    {
        int sLength = source.Length;
        GeoLibPointF[] ret = new GeoLibPointF[sLength];
#if !GWSINGLETHREADED
        Parallel.For(0, sLength, i =>
#else
            for (int i = 0; i < source.Length; i++)
#endif
            {
                ret[i] = new GeoLibPointF(source[i].X + x, source[i].Y + y);
            }
Example #6
0
    private static double pAngleBetweenPoints(GeoLibPointF interSection_A, GeoLibPointF interSection_B, GeoLibPointF interSection_C, bool allowNegative)
    {
        GeoLibPointF cBVector = new(interSection_B.X - interSection_C.X, interSection_B.Y - interSection_C.Y);
        GeoLibPointF cAVector = new(interSection_A.X - interSection_C.X, interSection_A.Y - interSection_C.Y);

        double xComponents = cBVector.X * cAVector.X;
        double yComponents = cBVector.Y * cAVector.Y;

        double scalarProduct = xComponents + yComponents;

        return(angleCalc(cAVector.X, cAVector.Y, cBVector.X, cBVector.Y, scalarProduct, allowNegative));
    }
Example #7
0
    private void write1Delta(GeoLibPointF p, bool dir)
    {
        int w = dir switch
        {
            true => (int)p.Y,
            _ => (int)p.X
        };

        switch (w)
        {
        case > 0:
            w <<= 1;
            break;

        default:
            w = (-w << 1) + 1;
            break;
        }
        writeUnsignedInteger((uint)w);
    }
Example #8
0
    public void writePointArray(GeoLibPoint[] p, bool excludeImplicid)
    {
        bool type0 = true;
        bool type1 = true;
        bool type2 = true;
        bool type3 = true;

        switch (p.Length % 2)
        {
        case 0:
            type0 = false;
            type1 = false;
            break;
        }
        switch (p.Length)
        {
        case < 4:
            type0 = false;
            type1 = false;
            break;
        }
        for (int i = 0; i < p.Length - 1; i++)
        {
            GeoLibPointF pd = GeoWrangler.distanceBetweenPoints_point(p[i + 1], p[i]);
            if (pd.Y != 0 && i % 2 != 0)
            {
                type1 = false;
            }

            if (pd.X != 0 && i % 2 != 0)
            {
                type0 = false;
            }

            if (pd.X != 0 && i % 2 != 1)
            {
                type1 = false;
            }

            if (pd.Y != 0 && i % 2 != 1)
            {
                type0 = false;
            }

            if (pd.X != 0 && pd.Y != 0)
            {
                type2 = false;
            }

            if (pd.X != 0 && pd.Y != 0 && Math.Abs(pd.X - pd.Y) > double.Epsilon && Math.Abs(pd.X - -pd.Y) > double.Epsilon)
            {
                type3 = false;
            }
        }
        switch (type0)
        {
        case true:
        {
            writeUnsignedInteger(0);
            int count = excludeImplicid switch
            {
                true => p.Length - 3,
                _ => p.Length - 1
            };
            writeUnsignedInteger((uint)count);
            GeoLibPoint last = new(p[0]);
            for (int i = 1; i <= count; i++)
            {
                GeoLibPointF h = GeoWrangler.distanceBetweenPoints_point(p[i], last);
                write1Delta(h, i % 2 == 0);
                last = new GeoLibPoint(p[i]);
            }

            break;
        }

        default:
        {
            switch (type1)
            {
            case true:
            {
                writeUnsignedInteger(1);
                int count = excludeImplicid switch
                {
                    true => p.Length - 3,
                    _ => p.Length - 1
                };
                writeUnsignedInteger((uint)count);
                GeoLibPoint last = new(p[0]);
                for (int i = 1; i <= count; i++)
                {
                    GeoLibPointF h = GeoWrangler.distanceBetweenPoints_point(p[i], last);
                    write1Delta(h, i % 2 == 1);
                    last = new GeoLibPoint(p[i]);
                }

                break;
            }

            default:
            {
                switch (type2)
                {
                case true:
                {
                    writeUnsignedInteger(2);
                    int count = excludeImplicid switch
                    {
                        true => p.Length - 2,
                        _ => p.Length - 1
                    };
                    writeUnsignedInteger((uint)count);
                    GeoLibPoint last = new(p[0]);
                    for (int i = 1; i <= count; i++)
                    {
                        GeoLibPointF h = GeoWrangler.distanceBetweenPoints_point(p[i], last);
                        write2Delta(h);
                        last = new GeoLibPoint(p[i]);
                    }

                    break;
                }

                default:
                {
                    switch (type3)
                    {
                    case true:
                    {
                        writeUnsignedInteger(3);
                        int count = excludeImplicid switch
                        {
                            true => p.Length - 2,
                            _ => p.Length - 1
                        };
                        writeUnsignedInteger((uint)count);
                        GeoLibPoint last = new(p[0]);
                        for (int i = 1; i <= count; i++)
                        {
                            GeoLibPointF h = GeoWrangler.distanceBetweenPoints_point(p[i], last);
                            write3Delta(h);
                            last = new GeoLibPoint(p[i]);
                        }

                        break;
                    }

                    default:
                    {
                        writeUnsignedInteger(4);
                        int count = excludeImplicid switch
                        {
                            true => p.Length - 2,
                            _ => p.Length - 1
                        };
                        writeUnsignedInteger((uint)count);
                        GeoLibPoint last = new(p[0]);
                        for (int i = 1; i <= count; i++)
                        {
                            GeoLibPointF h = GeoWrangler.distanceBetweenPoints_point(p[i], last);
                            writeGDelta(h);
                            last = new GeoLibPoint(p[i]);
                        }

                        break;
                    }
                    }

                    break;
                }
                }

                break;
            }
            }

            break;
        }
        }
    }
Example #9
0
            void pBoundingBox(List<PreviewShape> previewShapes)
            {
                if ((previewShapes == null) || (previewShapes.Count == 0))
                {
                    minX = 0;
                    maxX = 0;
                    minY = 0;
                    maxY = 0;
                    points = new List<GeoLibPointF>(4) { new GeoLibPointF(0, 0), new GeoLibPointF(0, 0), new GeoLibPointF(0, 0), new GeoLibPointF(0, 0) };
                    midPoint = new GeoLibPointF(0, 0);
                    return;
                }

                List<GeoLibPointF[]> pPoints = previewShapes[0].getPoints();

                if (pPoints.Count == 0)
                {
                    minX = 0;
                    maxX = 0;
                    minY = 0;
                    maxY = 0;
                    points = new List<GeoLibPointF>(4) { new GeoLibPointF(0, 0), new GeoLibPointF(0, 0), new GeoLibPointF(0, 0), new GeoLibPointF(0, 0) };
                    midPoint = new GeoLibPointF(0, 0);
                    return;
                }

                BoundingBox test;

                if (pPoints[0].Any())
                {
                    test = new BoundingBox(pPoints[0]);
                }
                else
                {
                    test = new BoundingBox(new[] { new GeoLibPointF(0, 0), new GeoLibPointF(0, 0), new GeoLibPointF(0, 0), new GeoLibPointF(0, 0) });
                }

                points = test.points.ToList();

                foreach (PreviewShape t in previewShapes)
                {
                    List<GeoLibPointF[]> polys = t.getPoints();
                    foreach (GeoLibPointF[] t1 in polys)
                    {
                        test = new BoundingBox(t1);

                        minX = test.points.Min(p => p.X);
                        if (minX < points[0].X)
                        {
                            // Reposition our min X points
                            points[0].X = minX;
                            points[1].X = minX;
                        }
                        minY = test.points.Min(p => p.Y);
                        if (minY < points[0].Y)
                        {
                            // Reposition our min Y points
                            points[0].Y = minY;
                            points[3].Y = minY;
                        }
                        maxX = test.points.Max(p => p.X);
                        if (maxX > points[2].X)
                        {
                            // Reposition our max X points
                            points[2].X = maxX;
                            points[3].X = maxX;
                        }
                        maxY = test.points.Max(p => p.Y);
                        if (maxY > points[2].Y)
                        {
                            // Reposition our max Y points
                            points[1].Y = maxY;
                            points[2].Y = maxY;
                        }
                    }
                }
                minX = points.Min(p => p.X);
                minY = points.Min(p => p.Y);
                maxX = points.Max(p => p.X);
                maxY = points.Max(p => p.Y);
                midPoint = new GeoLibPointF(minX + ((maxX - minX) / 2.0f), minY + ((maxY - minY) / 2.0f));
            }
 private void pGeoLibPointF(GeoLibPointF sourcePoint)
 {
     X = sourcePoint.X;
     Y = sourcePoint.Y;
 }
Example #11
0
 public void Offset(GeoLibPointF offset)
 {
     pOffset(offset);
 }
Example #12
0
 public static PointF myPointFToPointF(GeoLibPointF sourcePoint)
 {
     return new PointF((float)sourcePoint.X, (float)sourcePoint.Y);
 }
Example #13
0
    private static GeoLibPointF pDistanceBetweenPoints_point(GeoLibPointF pt1, GeoLibPointF pt2)
    {
        GeoLibPointF ret = new(pt1.X - pt2.X, pt1.Y - pt2.Y);

        return(ret);
    }
Example #14
0
 public static GeoLibPointF distanceBetweenPoints_point(GeoLibPointF pt1, GeoLibPointF pt2)
 {
     return(pDistanceBetweenPoints_point(pt1, pt2));
 }
Example #15
0
 private static double pDistanceBetweenPoints(GeoLibPointF pt1, GeoLibPointF pt2)
 {
     return(Math.Sqrt(Utils.myPow(pt1.X - pt2.X, 2) + Utils.myPow(pt1.Y - pt2.Y, 2)));
 }
Example #16
0
 public static double distanceBetweenPoints(GeoLibPointF pt1, GeoLibPointF pt2)
 {
     return(pDistanceBetweenPoints(pt1, pt2));
 }
Example #17
0
 public static double angleBetweenPoints(GeoLibPointF interSection_A, GeoLibPointF interSection_B, GeoLibPointF interSection_C, bool allowNegative = false)
 {
     return(pAngleBetweenPoints(interSection_A, interSection_B, interSection_C, allowNegative));
 }
 private void pOffset(GeoLibPointF offset)
 {
     X += offset.X;
     Y += offset.Y;
 }
Example #19
0
        decimal pDoX(int i)
        {
            decimal x_ = 0m;

            int xRef = pGetRef(i, PatternElement.properties_i.xPosRef);

            // We have a relative positioning situation.
            // Note that this could be cascading so we need to walk the stack
            if (xRef >= 0)
            {
                int sRef = pGetPatternElement(i).getInt(PatternElement.properties_i.xPosSubShapeRef);

                int sPosRef = pGetPatternElement(i).getInt(PatternElement.properties_i.xPosSubShapeRefPos);

                bool refFlipped = pGetPatternElement(xRef).getInt(PatternElement.properties_i.flipH) == 1;
                x_ += pGetPatternElement(xRef).getDecimal(PatternElement.properties_decimal.xPos);

                // In the case of an array shape type for the reference, we may still have subshape relative references. To check this, we need to query for an array. If we don't have an array, we're good.
                // Then we also need to query whether the subshape reference is a higher value than the number of subshapes in the shape; the 'array' subshape reference is last in the list.
                bool doX = !pGetPatternElement(xRef).isXArray() || (pGetPatternElement(xRef).isXArray() && (sRef < pGetPatternElement(xRef).getSubShapeCount()));

                int aXRef = xRef;
                // Is the array reference a relative array?
                if (pGetPatternElement(xRef).getInt(PatternElement.properties_i.arrayRef) != 0)
                {
                    aXRef = pGetPatternElement(xRef).getInt(PatternElement.properties_i.arrayRef) - 1;

                    int PSSR = pGetPatternElement(i).getInt(PatternElement.properties_i.xPosSubShapeRef);
                    int PSSC = pGetPatternElement(xRef).getSubShapeCount();
                    if (PSSR == PSSC)
                    {
                        doX = false;
                    }
                }

                if (doX)
                {
                    if (sRef == 1)
                    {
                        x_ += pGetPatternElement(xRef).getDecimal(PatternElement.properties_decimal.horOffset, 0);
                        if (pGetPatternElement(xRef).getInt(PatternElement.properties_i.shapeIndex) != (int)CommonVars.shapeNames.Sshape)
                        {
                            if ((pGetPatternElement(xRef).getInt(PatternElement.properties_i.shapeIndex) != (int)CommonVars.shapeNames.Ushape) && (pGetPatternElement(xRef).getInt(PatternElement.properties_i.shapeIndex) != (int)CommonVars.shapeNames.Xshape))
                            {
                                x_ += pGetPatternElement(xRef).getDecimal(PatternElement.properties_decimal.horLength, 0);
                            }
                            else
                            {
                                x_ += pGetPatternElement(xRef).getDecimal(PatternElement.properties_decimal.horOffset, 1);
                            }
                        }
                    }
                    if (sRef == 2)
                    {
                        x_ += pGetPatternElement(xRef).getDecimal(PatternElement.properties_decimal.horOffset, 0);
                        x_ += pGetPatternElement(xRef).getDecimal(PatternElement.properties_decimal.horOffset, 2);
                    }
                }

                // Process the side case.
                if ((!refFlipped && (sPosRef == (int)CommonVars.subShapeHorLocs.R)) || (refFlipped && (sPosRef == (int)CommonVars.subShapeHorLocs.L)))
                {
                    if (doX)
                    {
                        switch (sRef)
                        {
                            case 0:
                                x_ += pGetPatternElement(xRef).getDecimal(PatternElement.properties_decimal.horLength, 0);
                                break;
                            case 1:
                                x_ += pGetPatternElement(xRef).getDecimal(PatternElement.properties_decimal.horLength, 1);
                                break;
                            case 2:
                                x_ += pGetPatternElement(xRef).getDecimal(PatternElement.properties_decimal.horLength, 2);
                                break;
                        }
                    }
                    else
                    {
                        x_ += Convert.ToDecimal(pBBDimension(bbDims.width, aXRef));
                    }
                }

                if (sPosRef == (int)CommonVars.subShapeHorLocs.M)
                {
                    if (doX)
                    {
                        switch (sRef)
                        {
                            case 0:
                                x_ += pGetPatternElement(xRef).getDecimal(PatternElement.properties_decimal.horLength, 0) / 2;
                                break;
                            case 1:
                                x_ += pGetPatternElement(xRef).getDecimal(PatternElement.properties_decimal.horLength, 1) / 2;
                                break;
                            case 2:
                                x_ += pGetPatternElement(xRef).getDecimal(PatternElement.properties_decimal.horLength, 2) / 2;
                                break;
                        }
                    }
                    else
                    {
                        x_ += Convert.ToDecimal(pBBDimension(bbDims.width, aXRef)) / 2;
                    }
                }

                // Is the reference flipped? If so, we need to flip our value to get the correct result
                if (refFlipped)
                {
                    ShapeLibrary t = new ShapeLibrary(pGetPatternElement(xRef));
                    GeoLibPointF pivot = t.getPivotPoint();

                    bool alignX = pGetPatternElement(xRef).getInt(PatternElement.properties_i.alignX) == 1;
                    bool alignY = pGetPatternElement(xRef).getInt(PatternElement.properties_i.alignY) == 1;
                    x_ = Convert.ToDecimal(GeoWrangler.flip(true, false, alignX, alignY, pivot, new[] { new GeoLibPointF(Convert.ToDouble(x_), 0) })[0].X);
                }

                if (doX)
                {
                    switch (sRef)
                    {
                        case 0:
                            x_ += pGetPatternElement(i).getDecimal(PatternElement.properties_decimal.horOffset, 0);
                            break;
                        case 1:
                            x_ += pGetPatternElement(i).getDecimal(PatternElement.properties_decimal.horOffset, 1);
                            break;
                        case 2:
                            x_ += pGetPatternElement(i).getDecimal(PatternElement.properties_decimal.horOffset, 2);
                            break;
                    }
                }

                // xRef = pGetRef(xRef, PatternElement.properties_i.xPosRef);
            }

            return x_;
        }
Example #20
0
        decimal pDoY(int i)
        {
            decimal y_ = 0m;

            int yRef = pGetRef(i, PatternElement.properties_i.yPosRef);

            // We have a relative positioning situation.
            // Note that this could be cascading so we need to walk the stack

            if (yRef >= 0)
            {
                int sRef = pGetPatternElement(i).getInt(PatternElement.properties_i.yPosSubShapeRef);

                int sPosRef = pGetPatternElement(i).getInt(PatternElement.properties_i.yPosSubShapeRefPos);

                bool refFlipped = pGetPatternElement(yRef).getInt(PatternElement.properties_i.flipV) == 1;

                y_ += pGetPatternElement(yRef).getDecimal(PatternElement.properties_decimal.yPos);

                // In the case of an array shape type for the reference, we may still have subshape relative references. To check this, we need to query for an array. If we don't have an array, we're good.
                // Then we also need to query whether the subshape reference is a higher value than the number of subshapes in the shape; the 'array' subshape reference is last in the list.
                bool doY = !pGetPatternElement(yRef).isYArray() || (pGetPatternElement(yRef).isYArray() && (sRef < pGetPatternElement(yRef).getSubShapeCount()));

                int aYRef = yRef;

                // Is the array reference a relative array?
                if (pGetPatternElement(yRef).getInt(PatternElement.properties_i.arrayRef) != 0)
                {
                    aYRef = pGetPatternElement(yRef).getInt(PatternElement.properties_i.arrayRef) - 1;

                    int PSSR = pGetPatternElement(i).getInt(PatternElement.properties_i.yPosSubShapeRef);
                    int PSSC = pGetPatternElement(yRef).getSubShapeCount();
                    if (PSSR == PSSC)
                    {
                        doY = false;
                    }
                }

                if (doY)
                {
                    y_ += pGetPatternElement(yRef).getDecimal(PatternElement.properties_decimal.verOffset, 0);
                    if (sRef == 1)
                    {
                        y_ += pGetPatternElement(yRef).getDecimal(PatternElement.properties_decimal.verOffset, 1);
                    }
                    if (sRef == 2)
                    {
                        y_ += pGetPatternElement(yRef).getDecimal(PatternElement.properties_decimal.verLength, 0);
                        y_ -= pGetPatternElement(yRef).getDecimal(PatternElement.properties_decimal.verLength, 2);
                        y_ -= pGetPatternElement(yRef).getDecimal(PatternElement.properties_decimal.verOffset, 2);
                    }
                }

                // Process the side case.
                if ((!refFlipped && (sPosRef == (int)CommonVars.subShapeVerLocs.T)) || (refFlipped && (sPosRef == (int)CommonVars.subShapeVerLocs.B)))
                {
                    if (doY)
                    {
                        switch (sRef)
                        {
                            case 0:
                                y_ += pGetPatternElement(yRef).getDecimal(PatternElement.properties_decimal.verLength, 0);
                                break;
                            case 1:
                                y_ += pGetPatternElement(yRef).getDecimal(PatternElement.properties_decimal.verLength, 1);
                                break;
                            case 2:
                                y_ += pGetPatternElement(yRef).getDecimal(PatternElement.properties_decimal.verLength, 2);
                                break;
                        }
                    }
                    else
                    {
                        y_ += Convert.ToDecimal(pBBDimension(bbDims.height, aYRef));
                    }
                }

                if (sPosRef == (int)CommonVars.subShapeVerLocs.M)
                {
                    if (doY)
                    {
                        switch (sRef)
                        {
                            case 0:
                                y_ += pGetPatternElement(yRef).getDecimal(PatternElement.properties_decimal.verLength, 0) / 2;
                                break;
                            case 1:
                                y_ += pGetPatternElement(yRef).getDecimal(PatternElement.properties_decimal.verLength, 1) / 2;
                                break;
                            case 2:
                                y_ += pGetPatternElement(yRef).getDecimal(PatternElement.properties_decimal.verLength, 2) / 2;
                                break;
                        }
                    }
                    else
                    {
                        y_ += Convert.ToDecimal(pBBDimension(bbDims.height, aYRef)) / 2;
                    }
                }

                // Is the reference flipped? If so, we need to flip our value to get the correct result
                if (refFlipped)
                {
                    ShapeLibrary t = new ShapeLibrary(pGetPatternElement(yRef));
                    GeoLibPointF pivot = t.getPivotPoint();

                    bool alignX = pGetPatternElement(yRef).getInt(PatternElement.properties_i.alignX) == 1;
                    bool alignY = pGetPatternElement(yRef).getInt(PatternElement.properties_i.alignY) == 1;
                    y_ = Convert.ToDecimal(GeoWrangler.flip(false, true, alignX, alignY, pivot, new[] { new GeoLibPointF(0, Convert.ToDouble(y_)) })[0].Y);
                }

                if (doY)
                {
                    switch (sRef)
                    {
                        case 0:
                            y_ += pGetPatternElement(i).getDecimal(PatternElement.properties_decimal.verOffset, 0);
                            break;
                        case 1:
                            y_ += pGetPatternElement(i).getDecimal(PatternElement.properties_decimal.verOffset, 1);
                            break;
                        case 2:
                            break;
                    }
                }

                // yRef = pGetRef(yRef, PatternElement.properties_i.yPosRef);
            }

            return y_;

        }
Example #21
0
 private void pOffset(GeoLibPointF offset)
 {
     X += offset.X;
     Y += offset.Y;
     setOtherProps();
 }
 public GeoLibPointF(GeoLibPointF sourcePoint)
 {
     pGeoLibPointF(sourcePoint);
 }