public List <QDShapeDBPoint> getShapesNearPoint(QDPoint point, float radius)
        {
            // Get the ShapeSampledPoints near the query point
            List <QDPoint> pts = new List <QDPoint>();

            quadTree.getPoints(point, radius, pts);

            // Create a list of all the PointSets this corresponds to
            //HashMap<QDInputPointSet, HashSet<PointTypes>> returnPtSets = new HashMap<>();
            List <QDShapeDBPoint> returnPts = new List <QDShapeDBPoint>();

            foreach (QDPoint pt in pts)
            {
                returnPts.Add((QDShapeDBPoint)pt);
                //            QDInputPointSet ptSet = ptSets.get( ((ShapeSampledPoint)pt).objectID );
                //            HashSet<PointTypes> types = new HashSet<>();
                //            // check to see if the list already contains the PointSet
                //            if (returnPtSets.containsKey(ptSet)){
                //                types = returnPtSets.get(ptSet);
                //                types.add(((SampledPoint) pt).type);
                //            }
                //            else {
                //                types.add(((SampledPoint) pt).type);
                //
                //            }
                //            returnPtSets.put(ptSet, types);
            }

            return(returnPts);
        }
Exemple #2
0
        public void addPoint(QDPoint pt)
        {
            // If the current master node does not contain the point, keep increasing the square size until it does
            while (!masterNode.contains(pt))
            {
                bool  expandXPos = true; // Whether the quad tree should expand in positive or negative direction
                bool  expandYPos = true;
                float newCnrX, newCnrY;
                // Check where new point is located relative to current master node
                if (pt.x > masterNode.maxX)
                {
                    expandXPos = true;
                    newCnrX    = masterNode.minX;
                }
                else
                {
                    expandXPos = false;
                    newCnrX    = masterNode.minX - masterNode.width;
                }
                if (pt.y > masterNode.maxY)
                {
                    expandYPos = true;
                    newCnrY    = masterNode.minY;
                }
                else
                {
                    expandYPos = false;
                    newCnrY    = masterNode.minY - masterNode.height;
                }

                // Initialise new master node
                QuadNode newMaster = new QuadNode(newCnrX, newCnrY, masterNode.size * 2f);
                newMaster.topL = new QuadNode(newCnrX, newCnrY, masterNode.size);
                newMaster.topR = new QuadNode(newCnrX + masterNode.size, newCnrY, masterNode.size);
                newMaster.botL = new QuadNode(newCnrX, newCnrY + masterNode.size, masterNode.size);
                newMaster.botR = new QuadNode(newCnrX + masterNode.size, newCnrY + masterNode.size, masterNode.size);

                // Insert current master node into newMaster
                if (expandXPos && expandYPos)
                {
                    newMaster.topL = masterNode;
                }
                else if (expandXPos && !expandYPos)
                {
                    newMaster.botL = masterNode;
                }
                else if (!expandXPos && expandYPos)
                {
                    newMaster.topR = masterNode;
                }
                else
                {
                    newMaster.botR = masterNode;
                }

                masterNode = newMaster;
            }
            masterNode.addPoint(pt);
        }
Exemple #3
0
 public QDPoint getMidpoint()
 {
     if (midPoint == null)
     {
         midPoint = new QDPoint((start.x + finish.x) / 2.0f, (start.y + finish.y) / 2.0f);
     }
     return(midPoint);
 }
        public float getDistToPoint(QDPoint pt)
        {
            float a = this.coeffs[0];
            float b = this.coeffs[1];
            float c = this.coeffs[2];

            return((float)(Math.Abs(a * pt.x + b * pt.y + c) / Math.Sqrt(a * a + b * b)));
        }
        private void calcCoeffs(QDPoint pt, float angleD)
        {
            float sinA = (float)Math.Sin(QDUtils.QDUtils.toRadians(angleD));
            float cosA = (float)Math.Cos(QDUtils.QDUtils.toRadians(angleD));

            coeffs.Add(sinA);
            coeffs.Add(-cosA);
            coeffs.Add(cosA * pt.y - sinA * pt.x);
        }
Exemple #6
0
 public QDLine(QDPoint start_in, QDPoint finish_in)
 {
     start  = start_in;
     finish = finish_in;
     getMidpoint();
     length = (float)Math.Pow(Math.Pow(start.x - finish.x, 2.0f) + Math.Pow(start.y - finish.y, 2.0f), 0.5f);
     angleR = (float)Math.Atan2(finish.y - start.y, finish.x - start.x);
     angleD = (float)toDegrees(angleR);
     //path.moveTo(start.x, start.y);
     //path.QDLineTo(finish.x,finish.y);
 }
Exemple #7
0
        //@Override
        public List <QDShapeDBPoint> getIntermediatePoints(float spacing)
        {
            List <QDShapeDBPoint> intermediatePoints = new List <QDShapeDBPoint>();

            intermediatePoints.Add(new QDShapeDBPoint(centre, QDPointTypes.CIRCLE_CENTRE));
            if (radius > spacing)
            {
                float angleR     = 2.0f * (float)Math.Sin((spacing / 2.0f) / radius);
                int   numPts     = (int)Math.Ceiling(2.0f * Math.PI / angleR);
                float betweenPts = 2.0f * (float)Math.PI / numPts;
                for (int i = 1; i < numPts; i++)
                {
                    QDPoint pt = new QDPoint(centre.x + (float)Math.Cos(-180.0f + i * betweenPts) * radius, centre.y + (float)Math.Sin(-180.0f + i * betweenPts) * radius);
                    intermediatePoints.Add(new QDShapeDBPoint(pt, QDPointTypes.CIRCLE_CIRCUMFERENCE));
                }
            }
            return(intermediatePoints);
        }
Exemple #8
0
        //@Override
        public override List <QDShapeDBPoint> getIntermediatePoints(float spacing)
        {
            List <QDShapeDBPoint> intermediateQDPoints = new List <QDShapeDBPoint>();

            intermediateQDPoints.Add(new QDShapeDBPoint(start, QDPointTypes.LINE_START));
            intermediateQDPoints.Add(new QDShapeDBPoint(finish, QDPointTypes.LINE_FINISH));
            if (getLength() > spacing)
            {
                int   numPts     = (int)Math.Ceiling(getLength() / spacing);
                float betweenPts = getLength() / numPts;
                for (int i = 1; i < numPts; i++)
                {
                    QDPoint pt = new QDPoint(start.x + (float)Math.Cos(angleR) * i * betweenPts, start.y + (float)Math.Sin(angleR) * i * betweenPts);
                    intermediateQDPoints.Add(new QDShapeDBPoint(pt, QDPointTypes.LINE_INTERMEDIATE));
                }
            }
            return(intermediateQDPoints);
        }
Exemple #9
0
        // Create intermediate QDPoints by sweeping around a standard elliptical arc shape then manually
        // applying the rotation and translation to the QDPoint.
        //@Override
        public override List <QDShapeDBPoint> getIntermediatePoints(float spacing)
        {
            List <QDShapeDBPoint> pts = new List <QDShapeDBPoint>();
            // Get angle required to achieve desired QDPoint spacing at major axis extreme
            float angleStep = 2f * (float)Math.Atan(0.5f * spacing / mSemiX);

            // With a +ve CCW step, choose if we should sweep from start or finish to produce our arc
            float startSweep, finishSweep;

            if (direction == SweepDirection.Counterclockwise)
            {
                startSweep = QDUtils.QDUtils.degToRad(mStartAngleD); finishSweep = QDUtils.QDUtils.degToRad(mFinishAngleD);
            }
            else
            {
                startSweep = QDUtils.QDUtils.degToRad(mFinishAngleD); finishSweep = QDUtils.QDUtils.degToRad(mStartAngleD);
            }

            // Check whether the arc goes over the -pi barrier and adjust finish angle accordingly
            if (finishSweep < 0f && startSweep > finishSweep)
            {
                finishSweep += 2.0f * (float)Math.PI;
            }

            // Progress through the sweep
            for (float t = startSweep; t < finishSweep; t += angleStep)
            {
                QDPoint parametric   = new QDPoint(mSemiX * (float)Math.Cos(t), mSemiY * (float)Math.Sin(t));
                QDPoint rotatedPoint = new QDPoint((float)Math.Cos(mAngleR) * parametric.x - (float)Math.Sin(mAngleR) * parametric.y,
                                                   (float)Math.Sin(mAngleR) * parametric.x + (float)Math.Cos(mAngleR) * parametric.y);
                QDPoint        translatedPoint = new QDPoint(rotatedPoint.x + mCentre.x, rotatedPoint.y + mCentre.y);
                QDShapeDBPoint sampled         = new QDShapeDBPoint(translatedPoint, QDPointTypes.CIRCLE_CIRCUMFERENCE);
                pts.Add(sampled);
            }
            return(pts);
        }
        public QDInfiniteLine(QDPoint pt1, QDPoint pt2)
        {
            float angleR = (float)Math.Atan2(pt1.y - pt2.y, pt1.x - pt2.x);

            calcCoeffs(pt1, (float)QDUtils.QDUtils.toDegrees(angleR));
        }
 public QDInfiniteLine(QDPoint pt, float angleD)
 {
     calcCoeffs(pt, angleD);
 }
        //private void writeObject(ObjectOutputStream oos) throws IOException {

        //    // Default fields
        //    oos.defaultWriteObject();
        //    // write the object

        //    oos.writeInt(paint.getColor());
        //    oos.writeInt(paint.getAlpha());
        //    oos.writeFloat(paint.getStrokeWidth());
        //    oos.writeInt(Paint.Style.STROKE.ordinal());
        //    oos.writeInt(Paint.Join.ROUND.ordinal());

        //}

        //private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
        //    // default deserialization to fill the standard fields
        //    ois.defaultReadObject();
        //    // read back the additional data in the order we wrote it
        //    path = new Path();
        //    paint = new Paint();
        //    paint.setColor(ois.readInt());
        //    paint.setAlpha(ois.readInt());
        //    paint.setStrokeWidth(ois.readFloat());
        //    paint.setStyle(Paint.Style.values()[ois.readInt()]);
        //    paint.setStrokeJoin(Paint.Join.values()[ois.readInt()]);
        //}

        protected QDPoint absToLocCoords(QDPoint absPt, float SF, QDPoint origin)
        {
            return(new QDPoint((absPt.x - origin.x) * SF, (absPt.y - origin.y) * SF));
        }
Exemple #13
0
            public bool addPoint(QDPoint pt)
            {
                // Perform the check that the QDPoint is actually inside the region
                if (!this.contains(pt))
                {
                    return(false);
                }

                // If we're at size and have no children create them
                if (pts.Count >= child_per_branch && topL == null)
                {
                    subdivide();
                    pts.Add(pt);
                    foreach (QDPoint thisPt in pts)
                    {
                        if (topL.addPoint(thisPt))
                        {
                            continue;                       // Alternatively consider making the contains check a part of the addPoint function itself so it will return whether its possible to add or not
                        }
                        if (topR.addPoint(thisPt))
                        {
                            continue;
                        }
                        if (botL.addPoint(thisPt))
                        {
                            continue;
                        }
                        if (botR.addPoint(thisPt))
                        {
                            continue;
                        }
                    }
                    pts.Clear();
                }
                // if we already have children, add it to them
                else if (topL != null)
                {
                    if (topL.addPoint(pt))
                    {
                        return(true);
                    }
                    if (topR.addPoint(pt))
                    {
                        return(true);
                    }
                    if (botL.addPoint(pt))
                    {
                        return(true);
                    }
                    if (botR.addPoint(pt))
                    {
                        return(true);
                    }
                }
                // otherwise add it to the current node list
                else
                {
                    pts.Add(pt);
                }
                return(true);
            }
Exemple #14
0
 public QDShapeDBPoint(QDPoint pt, QDPointTypes type_in)  : base(pt)
 {
     type = type_in;
 }
Exemple #15
0
 // TODO: non-default direction - what does it even do?
 public QDCircle(QDPoint centrePt, float radiusLength)
 {
     centre = centrePt;
     radius = radiusLength;
     //direction = Path.Direction.CCW;
 }
Exemple #16
0
        public void getPoints(QDPoint pt, float radius, List <QDPoint> pts)
        {
            Square search = new Square(pt.x - radius, pt.y - radius, 2.0f * radius);

            masterNode.getPoints(search, pts);
        }
Exemple #17
0
 public QDPoint(QDPoint other)
 {
     this.x = other.x;
     this.y = other.y;
 }
Exemple #18
0
 public Boolean contains(QDPoint pt)
 {
     return(contains(pt.x, pt.y));
 }