public void ShapeGenerator_MatchesTemplate([ValueSource("shapeTypes")] ShapeType type) { ProBuilderMesh pb = ShapeGenerator.CreateShape(type); Assume.That(pb, Is.Not.Null); #if PB_CREATE_TEST_MESH_TEMPLATES // save a template mesh. the mesh is saved in a the Templates folder with the path extracted from: // Templates/{Asset Type}/{CallingFilePathRelativeToTests}/{MethodName}/{AssetName}.asset // note - pb_DestroyListener will not let pb_Object destroy meshes backed by an asset, so there's no need // to set `dontDestroyOnDelete` in the editor. TestUtility.SaveAssetTemplate(pb.GetComponent <MeshFilter>().sharedMesh, type.ToString()); #else try { TestUtility.AssertMeshAttributesValid(pb.mesh); // Loads an asset by name from the template path. See also pb_TestUtility.GetTemplatePath Mesh template = TestUtility.GetAssetTemplate <Mesh>(type.ToString()); Assert.IsTrue(TestUtility.AssertAreEqual(template, pb.mesh), type.ToString() + " value-wise mesh comparison"); } finally { Object.DestroyImmediate(pb.gameObject); } #endif }
public void GetShape_Line(out RayHitTestParameters line) { if (_shape != ShapeType.Line) { throw new InvalidOperationException("This class isn't set up for a line: " + _shape.ToString()); } line = new RayHitTestParameters(_point, _direction); }
private void CreateNewShape(ShapeType shapeType) { if (currentShape && currentShape.name == shapeType.ToString()) { return; } Destroy(currentShape); currentShape = new GameObject(shapeType.ToString()); currentShape.AddComponent(Type.GetType(shapeType.ToString())); }
protected override bool ValueEquals(MegaloScriptValueBase other) { var obj = (MegaloScriptShapeValue)other; bool equals = ShapeType == obj.ShapeType; switch (ShapeType) { case MegaloScriptShapeType.Sphere: equals &= Radius.Equals(obj.Radius); break; case MegaloScriptShapeType.Cylinder: equals &= Radius.Equals(obj.Radius) && Top.Equals(obj.Top) && Bottom.Equals(obj.Bottom); break; case MegaloScriptShapeType.Box: equals &= Radius.Equals(obj.Radius) && Length.Equals(obj.Length) && Top.Equals(obj.Top) && Bottom.Equals(obj.Bottom); break; case MegaloScriptShapeType.None: break; default: throw new KSoft.Debug.UnreachableException(ShapeType.ToString()); } return(equals); }
public override MegaloScriptValueBase Copy(MegaloScriptModel model) { var result = (MegaloScriptShapeValue)model.CreateValue(ValueType); result.ShapeType = ShapeType; switch (ShapeType) { case MegaloScriptShapeType.Sphere: result.Radius = Radius; break; case MegaloScriptShapeType.Cylinder: result.Radius = Radius; result.Top = Top; result.Bottom = Bottom; break; case MegaloScriptShapeType.Box: result.Radius = Radius; result.Length = Length; result.Top = Top; result.Bottom = Bottom; break; case MegaloScriptShapeType.None: break; default: throw new KSoft.Debug.UnreachableException(ShapeType.ToString()); } return(result); }
protected override void SerializeValue <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s) { s.StreamAttributeEnum("shapeType", ref mShapeType); switch (ShapeType) { case MegaloScriptShapeType.Sphere: using (s.EnterCursorBookmark(kVar0ElementName)) mRadius.SerializeCustom(model, s); break; case MegaloScriptShapeType.Cylinder: using (s.EnterCursorBookmark(kVar0ElementName)) mRadius.SerializeCustom(model, s); using (s.EnterCursorBookmark(kVar2ElementName)) mTop.SerializeCustom(model, s); using (s.EnterCursorBookmark(kVar3ElementName)) mBottom.SerializeCustom(model, s); break; case MegaloScriptShapeType.Box: using (s.EnterCursorBookmark("Width")) mRadius.SerializeCustom(model, s); using (s.EnterCursorBookmark(kVar1ElementName)) mLength.SerializeCustom(model, s); using (s.EnterCursorBookmark(kVar2ElementName)) mTop.SerializeCustom(model, s); using (s.EnterCursorBookmark(kVar3ElementName)) mBottom.SerializeCustom(model, s); break; case MegaloScriptShapeType.None: break; default: throw new KSoft.Debug.UnreachableException(ShapeType.ToString()); } }
public override void Serialize(MegaloScriptModel model, IO.BitStream s) { s.Stream(ref mShapeType, 2, MegaloScriptShapeTypeBitStreamer.Instance); switch (ShapeType) { case MegaloScriptShapeType.Sphere: mRadius.SerializeCustom(model, s); break; case MegaloScriptShapeType.Cylinder: mRadius.SerializeCustom(model, s); mTop.SerializeCustom(model, s); mBottom.SerializeCustom(model, s); break; case MegaloScriptShapeType.Box: mRadius.SerializeCustom(model, s); mLength.SerializeCustom(model, s); mTop.SerializeCustom(model, s); mBottom.SerializeCustom(model, s); break; case MegaloScriptShapeType.None: break; default: throw new KSoft.Debug.UnreachableException(ShapeType.ToString()); } }
/// <summary> /// Creates the requested shape and assigns proper row/column information /// </summary> /// <param name="type">Shape's type</param> /// <returns>A new shape with the requested</returns> private static Shape CreateShape(ShapeType type) { Color color = ColorFactory.RandomColor; switch (type) { case ShapeType.ShapeA: Shape sA = new Shape(shapeAModifiers); sA.Add(new Piece(0, 3, color)); sA.Add(new Piece(0, 4, color)); sA.Add(new Piece(1, 3, color)); sA.Add(new Piece(1, 4, color)); return(sA); case ShapeType.ShapeB: Shape sB = new Shape(shapeBModifiers); sB.Add(new Piece(0, 3, color)); sB.Add(new Piece(1, 3, color)); sB.Add(new Piece(2, 3, color)); return(sB); case ShapeType.ShapeC: Shape sC = new Shape(shapeCModifiers); sC.Add(new Piece(0, 4, color)); sC.Add(new Piece(0, 3, color)); sC.Add(new Piece(1, 3, color)); return(sC); default: throw new Exception(type.ToString()); } }
public virtual void PrintInfo() { Console.WriteLine(""); Console.WriteLine($"Figura: {type.ToString()}"); Console.WriteLine($"Nazwa: {name}"); Console.WriteLine($"Pole: {Surface}"); }
public string ToString(string setformat) { //will return the ints and doubles rounded to first decimal to string as a table string L = Math.Round(Length, 1).ToString(); string W = Math.Round(Width, 1).ToString(); string H = Math.Round(Height, 1).ToString(); string MA = Math.Round(MantelArea, 1).ToString(); string TSA = Math.Round(TotalSurfaceArea, 1).ToString(); string V = Math.Round(Volume, 1).ToString(); switch (setformat) { //R returns with ShapeType then values case "R": return(ShapeType.ToString() + " | " + L + "| " + W + "| " + H + "| " + MA + "| " + TSA + "| " + V); case "G": return(ToString()); case "": return(ToString()); default: //throws format exception if none of the cases match the if options throw new FormatException("Only R, G, or null can call ToSting method"); } }
/// <summary> /// Creates a new shape /// </summary> /// <param name="shapeType">The type of shape to be created</param> /// <returns>The created shape</returns> private static Shape CreateShape(ShapeType shapeType) { string type = Extensions.AsText(shapeType); Console.BackgroundColor = ConsoleColor.DarkRed; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(Properties.Strings.BoxLine); Console.WriteLine(Extensions.InsertEquals(Extensions.CenterAlignString(type, Properties.Strings.BoxLine))); Console.WriteLine(Properties.Strings.BoxLine); Console.ResetColor(); double[] Dimensions = ReadDimensions(shapeType); switch (shapeType.ToString()) { case "Cuboid": return(new Cuboid(Dimensions[0], Dimensions[1], Dimensions[2])); case "Cylinder": return(new Cylinder(Dimensions[0], Dimensions[1], Dimensions[2])); case "Ellipse": return(new Ellipse(Dimensions[0], Dimensions[1])); case "Rectangle": return(new Rectangle(Dimensions[0], Dimensions[1])); case "Sphere": return(new Sphere(Dimensions[0])); default: return(new Ellipse(Dimensions[0])); } }
public Sample GetTrainingSampleFromShapeFeatures(ShapeFeatures shapeFeatures, ShapeType shapeType) { return(new Sample { InputVector = GetInputVectorFromShapeFeatures(shapeFeatures), OutputClass = shapeType.ToString() }); }
public virtual XmlElement Save(XmlDocument xmlDoc) { XmlElement xmlNode = xmlDoc.CreateElement(TypeDescriptor.GetClassName(this)); xmlNode.SetAttribute("Pickable", pickable.ToString()); xmlNode.SetAttribute("Collidable", collidable.ToString()); xmlNode.SetAttribute("Interactable", interactable.ToString()); xmlNode.SetAttribute("ApplyGravity", applyGravity.ToString()); xmlNode.SetAttribute("Manipulatable", manipulatable.ToString()); xmlNode.SetAttribute("NeverDeactivate", neverDeactivate.ToString()); if (collisionGroupID != 0) { xmlNode.SetAttribute("CollisionGroupID", collisionGroupID.ToString()); } if (materialName.Length > 0) { xmlNode.SetAttribute("MaterialName", materialName); } xmlNode.SetAttribute("Mass", mass.ToString()); xmlNode.SetAttribute("ShapeType", shape.ToString()); if (shapeData.Count > 0) { String shapeDataStr = "" + shapeData[0]; for (int i = 1; i < shapeData.Count; ++i) { shapeDataStr += ", " + shapeData[i]; } xmlNode.SetAttribute("ShapeData", shapeDataStr); } if (!momentOfInertia.Equals(Vector3.Zero)) { xmlNode.SetAttribute("MomentOfInertia", momentOfInertia.ToString()); } if (!centerOfMass.Equals(Vector3.Zero)) { xmlNode.SetAttribute("CenterOfMass", centerOfMass.ToString()); } if (!initialLinearVelocity.Equals(Vector3.Zero)) { xmlNode.SetAttribute("InitialLinearVelocity", initialLinearVelocity.ToString()); } if (!initialAngularVelocity.Equals(Vector3.Zero)) { xmlNode.SetAttribute("InitialAngularVelocity", initialAngularVelocity.ToString()); } if (linearDamping != 0) { xmlNode.SetAttribute("LinearDamping", linearDamping.ToString()); } if (!angularDamping.Equals(-Vector3.One)) { xmlNode.SetAttribute("AngularDamping", angularDamping.ToString()); } return(xmlNode); }
protected void Update() { if (prevType != shapeType) { RebuildMesh(); } this.name = shapeType.ToString(); prevType = shapeType; }
public static FileError ShapeRecordShapeTypeMismatch(this IShapeFileRecordProblemBuilder builder, ShapeType expectedShapeType, ShapeType actualShapeType) { return(builder .Error(nameof(ShapeRecordShapeTypeMismatch)) .WithParameters( new ProblemParameter("ExpectedShapeType", expectedShapeType.ToString()), new ProblemParameter("ActualShapeType", actualShapeType.ToString())) .Build()); }
public static string Format(this ShapeType shape) { switch (shape) { case ShapeType.TrianglePyramid: return("Triangle Pyramid"); case ShapeType.SquarePyramid: return("Square Pyramid"); } return(shape.ToString()); }
private static void FilterShape() { ShapeType type = SelectShapeType(); foreach (var item in shapes) { if (item.GetShapeType().ToLower() == type.ToString()) { item.ToString(); } } }
void ShowRadius(ShapeType type, float radius, Color color) { GameObject go = new GameObject(type.ToString()); go.transform.SetParent(gameObject.transform); go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; var renderer = go.AddComponent <CircularRenderer>(); renderer.radius = radius; renderer.color = color; renderer.type = type; mShapeRenderers.Add(renderer); }
/// <summary> /// Translates the sent shapeType to a specific string meant for user to view /// </summary> /// <param name="shapeType">The shapeType to be translated</param> /// <returns>A translated shapeType. If a translation is missing, return a ToString()</returns> public static string AsText(this ShapeType shapeType) { switch (shapeType.ToString()) { case ("Rectangle"): return(Properties.Strings.Rectangle); case ("Circle"): return(Properties.Strings.Circle); case ("Ellipse"): return(Properties.Strings.Ellipse); case ("Cuboid"): return(Properties.Strings.Cuboid); case ("Cylinder"): return(Properties.Strings.Cylinder); case ("Sphere"): return(Properties.Strings.Sphere); } return(shapeType.ToString()); }
private void UpdateEnabledShapes() { for (int i = 0; i < transform.childCount; i++) { GameObject child = transform.GetChild(i).gameObject; if (child.name != _type.ToString()) { child.SetActive(false); } else { child.SetActive(true); } } }
protected PrimitiveObject GetPrimitiveObjectFromVertexData(IVertexData vertexData, ShapeType shapeType, EffectParameters effectParameters) { //instanicate the object PrimitiveObject primitiveObject = new PrimitiveObject("Archetype - " + shapeType.ToString(), ActorType.NotYetAssigned, Transform3D.Zero, effectParameters.Clone() as EffectParameters, StatusType.Update | StatusType.Drawn, vertexData); //add to the dictionary for re-use in any subsequent call to this method primitiveDictionary.Add(shapeType, primitiveObject); //return a reference to a CLONE of our original object - remember we always clone the dictionary object, rather than modify the archetype in the dictionary return(primitiveObject.Clone() as PrimitiveObject); }
public static void SetOffsetAndRotate_InLocalSpace_IsAppliedToMesh( [ValueSource("offsetRotationShapes")] ShapeType shape, [ValueSource("offsetValues")] Vector2 offset, [ValueSource("rotationValues")] float rotation) { var mesh = ShapeGenerator.CreateShape(shape); Assume.That(mesh, Is.Not.Null); try { foreach (var face in mesh.faces) { AutoUnwrapSettings uv = face.uv; uv.offset += new Vector2(.3f, .5f); uv.rotation = 35f; face.uv = uv; } mesh.ToMesh(); mesh.Refresh(); TestUtility.AssertMeshAttributesValid(mesh.mesh); string templateName = shape.ToString() + "offset: " + offset.ToString() + " rotation: " + rotation; #if PB_CREATE_TEST_MESH_TEMPLATES TestUtility.SaveAssetTemplate(mesh.mesh, mesh.name); #endif Mesh template = TestUtility.GetAssetTemplate <Mesh>(mesh.name); TestUtility.AssertAreEqual(template, mesh.mesh, message: mesh.name); } catch (System.Exception e) { Debug.LogError(e.ToString()); } finally { UnityEngine.Object.DestroyImmediate(mesh.gameObject); } }
void OnTriggerStay2D(Collider2D other) { if (gameManager.gameState != GameState.Playing) { return; } if (!gameManager.isWinning && other.gameObject.tag == (currentType.ToString() + "Hole")) { Debug.Log("win"); endDestination = other.gameObject.transform.position; gameManager.changeGameState(GameState.EndingAnimation); gameManager.isWinning = true; } else if (other.gameObject.tag == "Mechanism") { MechanicScript mechScript = other.GetComponent <MechanicScript> (); if (mechScript.type == currentType) { mechScript.ActivateMechanic(); } } else if (other.gameObject.tag == "Portal") { PortalScript portalScript = other.GetComponent <PortalScript> (); if (portalScript.type == currentType) { if (acceleration == 2.0f) { acceleration = 1.0f; } portalScript.UsePortal(this.gameObject); } } else if (other.gameObject.tag == "AccelZone" && acceleration == 1.0f) { acceleration = 2.0f; } }
/// <summary> /// Reads the dimensions of the specified shape from the user /// </summary> /// <param name="shapeType">The type of shape to ask the dimesions of</param> /// <returns>An array with the dimensions of the shape</returns> private static double[] ReadDimensions(ShapeType shapeType) { switch (shapeType.ToString()) { case "Cuboid": return(ReadDoublesGreaterThanZero(Properties.Strings.CuboidPrompt, 3)); case "Cylinder": return(ReadDoublesGreaterThanZero(Properties.Strings.CylinderPrompt, 3)); case "Ellipse": return(ReadDoublesGreaterThanZero(Properties.Strings.EllipsePrompt, 2)); case "Rectangle": return(ReadDoublesGreaterThanZero(Properties.Strings.RectanglePrompt, 2)); case "Sphere": return(ReadDoublesGreaterThanZero(Properties.Strings.SpherePrompt)); default: return(ReadDoublesGreaterThanZero(Properties.Strings.CirclePrompt)); } }
public string ToString(string setformat) { //will return the ints and doubles rounded to first decimal to string as a table string L = Math.Round(Length, 1).ToString(); string W = Math.Round(Width, 1).ToString(); string P = Math.Round(Perimeter, 1).ToString(); string A = Math.Round(Area, 1).ToString(); switch (setformat) { case "R": return(ShapeType.ToString() + " |" + L + " |" + W + " |" + P + " |" + A); case "G": return(ToString()); case null: return(ToString()); default: //sets throws new exception argument if setformat does not equal any of the cases throw new FormatException("Only R, G, or null calls the ToString method"); } }
/// <summary> /// Reads and parses the geometry with ID 'oid' from the ShapeFile /// </summary> /// <remarks><see cref="FilterDelegate">Filtering</see> is not applied to this method</remarks> /// <param name="oid">Object ID</param> /// <returns>geometry</returns> private Geometry ReadGeometry(uint oid) { _brShapeFile.BaseStream.Seek(GetShapeIndex(oid) + 8, 0); //Skip record number and content length var type = (ShapeType)_brShapeFile.ReadInt32(); //Shape type if (type == ShapeType.Null) { return(null); } if (_shapeType == ShapeType.Point || _shapeType == ShapeType.PointM || _shapeType == ShapeType.PointZ) { return(new Point(_brShapeFile.ReadDouble(), _brShapeFile.ReadDouble())); } if (_shapeType == ShapeType.Multipoint || _shapeType == ShapeType.MultiPointM || _shapeType == ShapeType.MultiPointZ) { _brShapeFile.BaseStream.Seek(32 + _brShapeFile.BaseStream.Position, 0); //skip min/max box var feature = new MultiPoint(); int nPoints = _brShapeFile.ReadInt32(); // get the number of points if (nPoints == 0) { return(null); } for (int i = 0; i < nPoints; i++) { feature.Points.Add(new Point(_brShapeFile.ReadDouble(), _brShapeFile.ReadDouble())); } return(feature); } if (_shapeType == ShapeType.PolyLine || _shapeType == ShapeType.Polygon || _shapeType == ShapeType.PolyLineM || _shapeType == ShapeType.PolygonM || _shapeType == ShapeType.PolyLineZ || _shapeType == ShapeType.PolygonZ) { _brShapeFile.BaseStream.Seek(32 + _brShapeFile.BaseStream.Position, 0); //skip min/max box int nParts = _brShapeFile.ReadInt32(); // get number of parts (segments) if (nParts == 0) { return(null); } int nPoints = _brShapeFile.ReadInt32(); // get number of points var segments = new int[nParts + 1]; //Read in the segment indexes for (int b = 0; b < nParts; b++) { segments[b] = _brShapeFile.ReadInt32(); } //add end point segments[nParts] = nPoints; if ((int)_shapeType % 10 == 3) { var mline = new MultiLineString(); for (int lineId = 0; lineId < nParts; lineId++) { var line = new LineString(); for (int i = segments[lineId]; i < segments[lineId + 1]; i++) { line.Vertices.Add(new Point(_brShapeFile.ReadDouble(), _brShapeFile.ReadDouble())); } mline.LineStrings.Add(line); } if (mline.LineStrings.Count == 1) { return(mline[0]); } return(mline); } else //(_ShapeType == ShapeType.Polygon etc...) { //First read all the rings var rings = new List <LinearRing>(); for (int ringId = 0; ringId < nParts; ringId++) { var ring = new LinearRing(); for (int i = segments[ringId]; i < segments[ringId + 1]; i++) { ring.Vertices.Add(new Point(_brShapeFile.ReadDouble(), _brShapeFile.ReadDouble())); } rings.Add(ring); } var isCounterClockWise = new bool[rings.Count]; int polygonCount = 0; for (int i = 0; i < rings.Count; i++) { isCounterClockWise[i] = rings[i].IsCCW(); if (!isCounterClockWise[i]) { polygonCount++; } } if (polygonCount == 1) //We only have one polygon { var poly = new Polygon { ExteriorRing = rings[0] }; if (rings.Count > 1) { for (int i = 1; i < rings.Count; i++) { poly.InteriorRings.Add(rings[i]); } } return(poly); } else { var mpoly = new MultiPolygon(); var poly = new Polygon { ExteriorRing = rings[0] }; for (var i = 1; i < rings.Count; i++) { if (!isCounterClockWise[i]) { mpoly.Polygons.Add(poly); poly = new Polygon(rings[i]); } else { poly.InteriorRings.Add(rings[i]); } } mpoly.Polygons.Add(poly); return(mpoly); } } } throw (new ApplicationException("Shapefile type " + _shapeType.ToString() + " not supported")); }
/// <summary> /// Reads and parses the geometry with ID 'oid' from the ShapeFile /// </summary> /// <remarks><see cref="FilterDelegate">Filtering</see> is not applied to this method</remarks> /// <param name="oid">Object ID</param> /// <returns>geometry</returns> private SharpMap.Geometries.Geometry ReadGeometry(uint oid) { brShapeFile.BaseStream.Seek(GetShapeIndex(oid) + 8, 0); //Skip record number and content length ShapeType type = (ShapeType)brShapeFile.ReadInt32(); //Shape type if (type == ShapeType.Null) { return(null); } if (_ShapeType == ShapeType.Point || _ShapeType == ShapeType.PointM || _ShapeType == ShapeType.PointZ) { SharpMap.Geometries.Point tempFeature = new SharpMap.Geometries.Point(); return(new SharpMap.Geometries.Point(brShapeFile.ReadDouble(), brShapeFile.ReadDouble())); } else if (_ShapeType == ShapeType.Multipoint || _ShapeType == ShapeType.MultiPointM || _ShapeType == ShapeType.MultiPointZ) { brShapeFile.BaseStream.Seek(32 + brShapeFile.BaseStream.Position, 0); //skip min/max box SharpMap.Geometries.MultiPoint feature = new SharpMap.Geometries.MultiPoint(); int nPoints = brShapeFile.ReadInt32(); // get the number of points if (nPoints == 0) { return(null); } for (int i = 0; i < nPoints; i++) { feature.Points.Add(new SharpMap.Geometries.Point(brShapeFile.ReadDouble(), brShapeFile.ReadDouble())); } return(feature); } else if (_ShapeType == ShapeType.PolyLine || _ShapeType == ShapeType.Polygon || _ShapeType == ShapeType.PolyLineM || _ShapeType == ShapeType.PolygonM || _ShapeType == ShapeType.PolyLineZ || _ShapeType == ShapeType.PolygonZ) { brShapeFile.BaseStream.Seek(32 + brShapeFile.BaseStream.Position, 0); //skip min/max box int nParts = brShapeFile.ReadInt32(); // get number of parts (segments) if (nParts == 0) { return(null); } int nPoints = brShapeFile.ReadInt32(); // get number of points int[] segments = new int[nParts + 1]; //Read in the segment indexes for (int b = 0; b < nParts; b++) { segments[b] = brShapeFile.ReadInt32(); } //add end point segments[nParts] = nPoints; if ((int)_ShapeType % 10 == 3) { SharpMap.Geometries.MultiLineString mline = new SharpMap.Geometries.MultiLineString(); for (int LineID = 0; LineID < nParts; LineID++) { SharpMap.Geometries.LineString line = new SharpMap.Geometries.LineString(); for (int i = segments[LineID]; i < segments[LineID + 1]; i++) { line.Vertices.Add(new SharpMap.Geometries.Point(brShapeFile.ReadDouble(), brShapeFile.ReadDouble())); } mline.LineStrings.Add(line); } if (mline.LineStrings.Count == 1) { return(mline[0]); } return(mline); } else //(_ShapeType == ShapeType.Polygon etc...) { //First read all the rings List <SharpMap.Geometries.LinearRing> rings = new List <SharpMap.Geometries.LinearRing>(); for (int RingID = 0; RingID < nParts; RingID++) { SharpMap.Geometries.LinearRing ring = new SharpMap.Geometries.LinearRing(); for (int i = segments[RingID]; i < segments[RingID + 1]; i++) { ring.Vertices.Add(new SharpMap.Geometries.Point(brShapeFile.ReadDouble(), brShapeFile.ReadDouble())); } rings.Add(ring); } bool[] IsCounterClockWise = new bool[rings.Count]; int PolygonCount = 0; for (int i = 0; i < rings.Count; i++) { IsCounterClockWise[i] = rings[i].IsCCW(); if (!IsCounterClockWise[i]) { PolygonCount++; } } if (PolygonCount == 1) //We only have one polygon { SharpMap.Geometries.Polygon poly = new SharpMap.Geometries.Polygon(); poly.ExteriorRing = rings[0]; if (rings.Count > 1) { for (int i = 1; i < rings.Count; i++) { poly.InteriorRings.Add(rings[i]); } } return(poly); } else { SharpMap.Geometries.MultiPolygon mpoly = new SharpMap.Geometries.MultiPolygon(); SharpMap.Geometries.Polygon poly = new SharpMap.Geometries.Polygon(); poly.ExteriorRing = rings[0]; for (int i = 1; i < rings.Count; i++) { if (!IsCounterClockWise[i]) { mpoly.Polygons.Add(poly); poly = new SharpMap.Geometries.Polygon(rings[i]); } else { poly.InteriorRings.Add(rings[i]); } } mpoly.Polygons.Add(poly); return(mpoly); } } } else { throw (new ApplicationException("Shapefile type " + _ShapeType.ToString() + " not supported")); } }
public ShapeOverlay( TourStop owner, ShapeType shapeType) { ShapeType = shapeType; this.Owner = owner; this.Name = owner.GetNextDefaultName(shapeType.ToString()); }
public string GetLanguageTextForShape(ShapeType shape) { var key = shape.ToString().ToLower(); return(GetResourceText(key)); }
public override string ToString() { return(elementType.ToString() + " " + shape.ToString() + " (" + magnitude + ")"); }
public string GetLanguageTextForShape(ShapeType shape) { var key = shape.ToString().ToLower(); return GetResourceText(key); }
public void ImportFromBinaryReader(ShapeType shapeType, BinaryReader br) { try { long streamLength = br.BaseStream.Length; RecordNumber = NumericsHelper.ReverseInt(br.ReadInt32()); // Big, Reverse for actual value ContentLength = NumericsHelper.ReverseInt(br.ReadInt32()); // Big, Reverse for actual value ShapeType = (ShapeType)br.ReadInt32(); if (ShapeType == ShapeType.Null || shapeType == ShapeType.Null) { return; } if (ShapeType != shapeType) { // Shape Type doesn't match type specified in file header. According to specs, this is invalid. Throw exception throw new Exception( $"Unable to process shape! File shape of {shapeType} does not match record shape of {ShapeType} which violates ESRI specifications for shape files!"); } ShapeClass shapeClass = ShapeClass.Coordinate; bool hasMultiplePoints = true; bool hasParts = true; bool hasPartTypes = false; switch (shapeType) { case ShapeType.MultiPatch: shapeClass = ShapeClass.Depth; hasPartTypes = true; break; case ShapeType.MultiPoint: hasParts = false; break; case ShapeType.MultiPointM: shapeClass = ShapeClass.Measurement; hasParts = false; break; case ShapeType.MultiPointZ: shapeClass = ShapeClass.Depth; hasParts = false; break; case ShapeType.Null: throw new Exception( "The application should have never gotten to this point.\r\nSomething is wrong with the code!\r\nLYNCH THE DEVELOPER!"); case ShapeType.Point: hasMultiplePoints = false; hasParts = false; break; case ShapeType.PointM: shapeClass = ShapeClass.Measurement; hasMultiplePoints = false; hasParts = false; break; case ShapeType.PointZ: shapeClass = ShapeClass.Depth; hasMultiplePoints = false; hasParts = false; break; case ShapeType.Polygon: case ShapeType.Polyline: break; case ShapeType.PolygonM: shapeClass = ShapeClass.Measurement; break; case ShapeType.PolygonZ: shapeClass = ShapeClass.Depth; break; case ShapeType.PolylineM: shapeClass = ShapeClass.Measurement; break; case ShapeType.PolylineZ: shapeClass = ShapeClass.Depth; break; default: throw new Exception($"Unable to process shape! Record Shape of {ShapeType} is unknown!"); } if (hasMultiplePoints) { XMin = br.ReadDouble(); YMin = br.ReadDouble(); XMax = br.ReadDouble(); YMax = br.ReadDouble(); } NumberOfParts = hasParts ? br.ReadInt32() : 1; NumberOfPoints = hasMultiplePoints ? br.ReadInt32() : 1; //Console.Write(StringHelper.GetProgressString(br.BaseStream.Position, streamLength, "Shape")); List <Part> parts = new List <Part>(); for (int i = 0; i < NumberOfParts; i++) // Grab the parts { Part part = new Part { ShapeId = Id, SortIndex = i, PartTypeId = -1, // TODO: Find out what the appropriate part types are (if necessary) StartIndex = hasParts ? br.ReadInt32() : 0 // Get the start index }; parts.Add(part); if (i > 0) // If this isn't the first element { parts[i - 1].EndIndex = parts[i].StartIndex - 1; } // Set the last element's end index to this element's start index minus one if (i + 1 == NumberOfParts) // If this is the last element { parts[i].EndIndex = NumberOfPoints - 1; } // Set the ending index to the number of points minus one (to account for 0 based index) //Console.Write(StringHelper.GetProgressString(br.BaseStream.Position, streamLength, $"Part {i}")); } for (int i = 0; i < NumberOfParts; i++) // Set the number of points. This is done after initial grab to account for first/last elements { if (hasParts && hasPartTypes) { parts[i].PartTypeId = br.ReadInt32(); } parts[i].NumberOfPoints = parts[i].EndIndex - parts[i].StartIndex + 1; //Console.Write(StringHelper.GetProgressString(br.BaseStream.Position, streamLength, $"Part {i}")); } for (int i = 0; i < NumberOfParts; i++) // For each part { for (int j = 0; j < parts[i].NumberOfPoints; j++) // For each point in each part { parts[i].Points.Add(new Point { SortIndex = j, X = br.ReadDouble(), Y = br.ReadDouble() }); // Grab the point //Console.Write(StringHelper.GetProgressString(br.BaseStream.Position, streamLength, $"Part {i} | Point {j}")); } } if (shapeClass == ShapeClass.Depth) { if (hasMultiplePoints) { ZMin = br.ReadDouble(); ZMax = br.ReadDouble(); } for (int i = 0; i < NumberOfParts; i++) { for (int j = 0; j < parts[i].NumberOfPoints; j++) { //Console.Write(StringHelper.GetProgressString(br.BaseStream.Position, // streamLength, // $"Part {i} | Point {j} | Setting Z Value")); parts[i].Points.ToArray()[j].Z = br.ReadDouble(); } } } if (shapeClass == ShapeClass.Depth || shapeClass == ShapeClass.Measurement) { if (hasMultiplePoints) { MMin = br.ReadDouble(); MMax = br.ReadDouble(); } for (int i = 0; i < NumberOfParts; i++) { for (int j = 0; j < parts[i].NumberOfPoints; j++) { //Console.Write(StringHelper.GetProgressString(br.BaseStream.Position, // streamLength, // $"Part {i} | Point {j} | Setting M Value")); parts[i].Points.ToArray()[j].M = br.ReadDouble(); } } } try { string wktTemplate = "{0}({1})"; string shapeTypeName = ShapeType.ToString().ToUpperInvariant().Replace("POLYLINE", "MULTILINESTRING"); IReadOnlyCollection <string> coordinateStrings = parts.Select(s => s.CoordinateString).ToArray(); if (ShapeType == ShapeType.Point || ShapeType == ShapeType.PointZ || ShapeType == ShapeType.PointM) { coordinateStrings = coordinateStrings.Select(s => s.Trim('(').Trim(')').Trim()).ToArray(); } string coordinateString = string.Join(",", coordinateStrings); string wktString = string.Format(wktTemplate, shapeTypeName, coordinateString); //Debug.WriteLine(wktString); Geometry = DbGeometry.FromText(wktString, SRID); } catch (Exception e) { Console.WriteLine($"\r\n{e.Message}\r\n{e}"); throw; } } catch (Exception e) { Console.WriteLine($"\r\n{e.Message}\r\n{e}"); throw; } }