Exemple #1
0
        internal void AdjustCoordinate(GeoPoint p)
        {
#if DEBUG
            if (1070 == this.hashCode || 1063 == this.hashCode)
            {
            }
#endif
            GeoPoint mp = new GeoPoint(position, p); // point in between the two starting positions
            // collect all involved surfaces
            Set <Face> surfaces = new Set <Face>();
            foreach (Edge edg in edges)
            {
                surfaces.Add(edg.PrimaryFace);
                if (edg.SecondaryFace != null)
                {
                    surfaces.Add(edg.SecondaryFace);
                }
            }
            // find surfaces, which are not tangential at this position
            Dictionary <GeoVector, Face> nonTangentialSurfaces = new Dictionary <GeoVector, Face>();
            foreach (Face srf in surfaces)
            {
                GeoVector n = srf.Surface.GetNormal(srf.Surface.PositionOf(mp));
                if (n.IsNullVector())
                {
                    continue;                   // a pole
                }
                bool found = false;
                foreach (KeyValuePair <GeoVector, Face> kv in nonTangentialSurfaces)
                {
                    GeoVector cross = kv.Key.Normalized ^ n.Normalized;
                    double    cl    = cross.Length;
                    if (cl < 1e-3)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    nonTangentialSurfaces[n] = srf;
                }
            }
            if (nonTangentialSurfaces.Count >= 3)
            {
                Face[] fcs = new Face[nonTangentialSurfaces.Count];
                nonTangentialSurfaces.Values.CopyTo(fcs, 0);
                GeoPoint2D uv1, uv2, uv3;
                Surfaces.NewtonIntersect(fcs[0].Surface, fcs[0].Area.GetExtent(), fcs[1].Surface, fcs[1].Area.GetExtent(), fcs[2].Surface, fcs[2].Area.GetExtent(), ref mp, out uv1, out uv2, out uv3);
                if ((!fcs[0].Area.Contains(uv1, true) && fcs[0].Area.Distance(uv1) > fcs[0].Area.GetExtent().Size * 1e-4) ||
                    (!fcs[1].Area.Contains(uv2, true) && fcs[1].Area.Distance(uv2) > fcs[0].Area.GetExtent().Size * 1e-4) ||
                    (!fcs[2].Area.Contains(uv3, true) && fcs[2].Area.Distance(uv3) > fcs[2].Area.GetExtent().Size * 1e-4))
                {
                    mp = position; // invalid recalculation, e.g.: three planes with a common intersection line like in 3567_0005_01_02.stp
                }
            }
            else if (nonTangentialSurfaces.Count == 2)
            {   // use the two non tangential surfaces and a plane perpendicular to both surfaces in that point
                // to calculate a good point
                Face[]      fcs = new Face[nonTangentialSurfaces.Count];
                GeoVector[] nrm = new GeoVector[nonTangentialSurfaces.Count];
                nonTangentialSurfaces.Values.CopyTo(fcs, 0);
                nonTangentialSurfaces.Keys.CopyTo(nrm, 0);
                PlaneSurface pls = new PlaneSurface(new Plane(mp, nrm[0], nrm[1]));
                GeoPoint2D   uv1, uv2, uv3;
                Surfaces.NewtonIntersect(fcs[0].Surface, fcs[0].Area.GetExtent(), fcs[1].Surface, fcs[1].Area.GetExtent(), pls, BoundingRect.HalfInfinitBoundingRect, ref mp, out uv1, out uv2, out uv3);
            }

            position = mp;
            foreach (Edge edg in edges)
            {
                if (edg.Curve3D != null && edg.Vertex1 != edg.Vertex2)
                {
                    try
                    {
                        if (edg.Vertex1 == this && !Precision.IsEqual(edg.Curve3D.EndPoint, mp))
                        {
                            edg.Curve3D.StartPoint = mp;
                        }
                        else if (edg.Vertex2 == this && !Precision.IsEqual(edg.Curve3D.StartPoint, mp))
                        {
                            edg.Curve3D.EndPoint = mp;
                        }
                        else if (edg.Vertex1 != this && edg.Vertex2 != this)
                        {
                            throw new ApplicationException("Edge-Vertex mismatch");
                        }
                    }
                    catch { }
                }
            }
        }