//Question 21 public static void PrintTriangle(TriangleType triangleType, int height) { switch (triangleType) { case TriangleType.LeftAligned: LeftAligned(height); break; case TriangleType.Center: Center(height); break; case TriangleType.RightAligned: RightAligned(height); break; case TriangleType.InvertedLeftAligned: InvertedLeftAligned(height); break; case TriangleType.InvertedCenter: InvertedCenter(height); break; case TriangleType.InvertedRightAligned: InvertedRightAligned(height); break; } }
static List <Point> toVertecies(int width, int height, TriangleType type) { List <Point> verts = new List <Point>(); switch (type) { case TriangleType.BottomLeft: verts.Add(new Point(-width / 2, height / 2)); verts.Add(new Point(-width / 2, -height / 2)); verts.Add(new Point(width / 2, -height / 2)); break; case TriangleType.BottomRight: verts.Add(new Point(width / 2, height / 2)); verts.Add(new Point(-width / 2, -height / 2)); verts.Add(new Point(width / 2, -height / 2)); break; case TriangleType.UpperLeft: verts.Add(new Point(width / 2, height / 2)); verts.Add(new Point(-width / 2, height / 2)); verts.Add(new Point(-width / 2, -height / 2)); break; case TriangleType.UpperRight: verts.Add(new Point(width / 2, height / 2)); verts.Add(new Point(-width / 2, height / 2)); verts.Add(new Point(width / 2, -height / 2)); break; } return(verts); }
public void WhatShapeIsThisTest2() { MyRedPill redPill = new MyRedPill(); TriangleType type = redPill.WhatShapeIsThis(2, 2, 1); Assert.AreEqual(type, TriangleType.Isosceles); }
public void Scalene_TriangleTest() { TriangleModel tm = new TriangleModel("40", "10", "30"); TriangleType testtype = tm.GetTriangleType(tm); Assert.AreEqual(TriangleType.Scalene.ToString(), testtype.ToString()); }
public TriangleType getTriangleTypeTest([PexAssumeUnderTest] Triangle target) { TriangleType result = target.getTriangleType(); return(result); // TODO: add assertions to method TriangleTest.getTriangleTypeTest(Triangle) }
// 获得三角形类型描述 public static string GetTriangleType(TriangleDefinition triangle) { TriangleType type = TriangleType.CommonTriangle; // 判断类型 if (!IsTriangle(triangle)) { type = TriangleType.InvalidTriangle; } else if (IsRightTriangle(triangle)) { type = TriangleType.RightTriangle; } else if (IsEquilateralTriangle(triangle)) { type = TriangleType.EquilateralTriangle; } else if (IsoscelesTriangle(triangle)) { type = TriangleType.IsoscelesTriangle; } // 返回类型描述字符串 return(type.GetDescription()); }
public void WhatShapeIsThisTest5() { MyRedPill redPill = new MyRedPill(); TriangleType type = redPill.WhatShapeIsThis(2, 1, 3); Assert.AreEqual(type, TriangleType.Error); }
static void Main() { try { int[] sides = new int[3]; bool isInvalidSides = false; for (int index = 0; index < 3; index++) { Console.WriteLine($"Введите число №{index + 1}:"); string str = Console.ReadLine(); isInvalidSides |= !(int.TryParse(str, out sides[index])); } if (isInvalidSides) { Console.WriteLine("Введённые значения не являются целыми числами из диапазона [1..2147483647]."); } TriangleType result = Triangle.CheckTypeOfTriangle(sides); Console.WriteLine($"Результат: треугольник {ResultMessage[result]}."); } catch (Exception e) { Console.WriteLine(e.Message); } }
public Triangle() { mytriangletype = TriangleType.Unknown; A = 0; B = 0; C = 0; }
public static TriangleType GetTriangleType(int a, int b, int c) { TriangleType type = new TriangleType(); int[] values = new int[3] { a, b, c }; if ((a + b) > c || (b + c) > a || (a + c) > b) { if (values.Distinct().Count() == 1) { type = TriangleType.Equilateral; } else if (values.Distinct().Count() == 2) { type = TriangleType.Isosceles; } else if (values.Distinct().Count() == 3) { type = TriangleType.Scalene; } } else { type = TriangleType.Error; } if (a <= 0 || b <= 0 || c <= 0) { type = TriangleType.Error; } return(type); }
public void NonIntergerError_TriangleTest() { TriangleModel tm = new TriangleModel("Test", "0", "0"); TriangleType testtype = tm.GetTriangleType(tm); Assert.AreEqual(TriangleType.Error.ToString(), testtype.ToString()); }
private void FindTriangleType() { if (_a <= 0 || _b <= 0 || _c <= 0) { TriangleType = TriangleType.Error; return; } if (_a + _b <= _c || _b + _c <= _a || _c + _a <= _b) { TriangleType = TriangleType.Error; return; } int[] sides = new int[] { _a, _b, _c }; int distinctSideCount = sides.Distinct().Count(); if (distinctSideCount == 1) { TriangleType = TriangleType.Equilateral; } if (distinctSideCount == 2) { TriangleType = TriangleType.Isosceles; return; } if (distinctSideCount == 3) { TriangleType = TriangleType.Scalene; return; } }
public void Isosceles_TriangleTest() { TriangleModel tm = new TriangleModel("30", "30", "40"); TriangleType testtype = tm.GetTriangleType(tm); Assert.AreEqual(TriangleType.Isosceles.ToString(), testtype.ToString()); }
private void TriangleTopicDataAvailable(ShapeTypeDataReader dr) { List <ShapeType> samples = new List <ShapeType>(); List <SampleInfo> infos = new List <SampleInfo>(); ReturnCode error = dr.Take(samples, infos); if (error == ReturnCode.Ok) { for (int i = 0; i < samples.Count; i++) { SampleInfo info = infos[i]; ShapeType sample = samples[i]; if (info.ValidData) { int x = Convert.ToInt32((sample.x - (sample.shapesize / 2)) * _factorX); int y = Convert.ToInt32((sample.y - (sample.shapesize / 2)) * _factorY); TriangleType square = new TriangleType { Color = sample.color, X = x, Y = y, Size = sample.shapesize, PublicationHandle = info.PublicationHandle }; TriangleUpdated?.Invoke(this, square); } } } }
public void WhatShapeIsThisTest3() { MyRedPill redPill = new MyRedPill(); TriangleType type = redPill.WhatShapeIsThis(2, 2, 2); Assert.AreEqual(type, TriangleType.Equilateral); }
/// <summary> /// Create a triangle of given type. /// </summary> /// <param name="type">Type of triangle to produce.</param> public Triangle(TriangleType type) : base(2, 2) { _type = type; // Re-build the triangle with type information Build(); }
private void BtnTriangleType_Click(object sender, EventArgs e) { if (!ValidateFields()) { MessageBox.Show("Campos inválidos!\nPreencha os campos com apenas números"); return; } double sideA, sideB, sideC; ValidateSide(txtSideA, out sideA); ValidateSide(txtSideB, out sideB); ValidateSide(txtSideC, out sideC); TriangleType triangleType = TypeOfTriangle(sideA, sideB, sideC); if (triangleType == TriangleType.Equilateral) { lblTriangleType.Text = "O tipo desse triângulo é Equilatero!"; return; } if (triangleType == TriangleType.Isosceles) { lblTriangleType.Text = "O tipo desse triângulo é Isosceles!"; return; } if (triangleType == TriangleType.Scalene) { lblTriangleType.Text = "O tipo desse triângulo é Escaleno!"; return; } lblTriangleType.Text = "Esses lados não formam um triângulo!"; }
public void NegativeError_TriangleTest() { TriangleModel tm = new TriangleModel("-40", "10", "30"); TriangleType testtype = tm.GetTriangleType(tm); Assert.AreEqual(TriangleType.Error.ToString(), testtype.ToString()); }
/// <summary> /// Checking list of digits that they are really the dimensions of sides of triangle /// </summary> /// <param name="a">The first size of side</param> /// <param name="b">The second size of side</param> /// <param name="c">The third size of side</param> /// <returns>The triangle type</returns> public static TriangleType WhatShapeIsThis(int a, int b, int c) { Trace.TraceInformation("Start method WhatShape is this: {0} {1} {2}", a, b, c); TriangleType result = TriangleType.Error; try { if (a < 1 || b < 1 || c < 1 || a + (long)b <= c || b + (long)c <= a || c + (long)a <= b) { return(result = TriangleType.Error); } if (a == b && b == c) { return(result = TriangleType.Equilateral); } if (a == b || a == c || b == c) { return(result = TriangleType.Isosceles); } return(result = TriangleType.Scalene); } finally { Trace.TraceInformation("Finish method WhatShape is this: {0} {1} {2}. Result: {3}", a, b, c, result); } }
public Triangle(int a, int b, int c) { if (c < 0 || b < 0 || a < 0) { throw new Exception("negative"); } else { A = a; B = b; C = c; } if ((int)Math.Pow(A, 2) + (int)Math.Pow(B, 2) == (int)Math.Pow(C, 2)) { Type = TriangleType.Rectangular; } else if ((int)Math.Pow(A, 2) + (int)Math.Pow(B, 2) > (int)Math.Pow(C, 2)) { Type = TriangleType.Isosceles; } else if (A == B && A == C) { Type = TriangleType.Equilateral; } else { throw new Exception("Nonexistent triangle"); } }
public Triangle(int a, int b, int c) { this.a = a; this.b = b; this.c = c; this.TriangleType = GetTriangleType(); }
public void GetTriangleType_NotTriangle_ReturnsNotTriangleType(params string[] sides) { BigInteger[] parsedSides = sides.Select(side => BigInteger.Parse(side)).ToArray(); TriangleType resultType = TriangleProgram.GetTriangleType(parsedSides); Assert.Equal(Triangle.TriangleType.NotTriangle, resultType); }
private void DetermineTriangleType() { //validate triangle if (!ValidateTriangle()) { TriangleType = TriangleType.Error; return; } var numberOfUniqueSides = sides.Distinct().Count(); //determine the type of triangle from number of unique lengths switch (numberOfUniqueSides) { case 1://all the same length TriangleType = TriangleType.Equilateral; break; case 2://has two different lengths TriangleType = TriangleType.Isosceles; break; case 3://has three different lengths TriangleType = TriangleType.Scalene; break; default://execution shouldn't be able to reach here throw new ArgumentException(); } }
/// <summary> /// Determines the type of triangle /// </summary> public static void TriangleClassifier() { // read triangles sides string side1 = Console.ReadLine(); string side2 = Console.ReadLine(); string side3 = Console.ReadLine(); // classify triangle TriangleType type = TypeTriangle(side1, side2, side3); if (type == TriangleType.EQUILATERAL) { Console.WriteLine("Triangle is equilateral"); } else if (type == TriangleType.ISOSCELES) { Console.WriteLine("Triangle is isosceles"); } else if (type == TriangleType.SCALENE) { Console.WriteLine("Triangle is scalene"); } else if (type == TriangleType.TRIANGLE_INEQUALITY) { Console.WriteLine("Triangle inequality did not hold"); } else if (type == TriangleType.NONE) { Console.WriteLine("Triangle sides were not valid"); } else { throw new ArgumentException("Unknown triangle type"); } }
public void WhatShapeIsThisTest7() { MyRedPill redPill = new MyRedPill(); TriangleType type = redPill.WhatShapeIsThis(12, 6, 14); Assert.AreEqual(type, TriangleType.Scalene); }
public void Equilateral_TriangleTest() { TriangleModel tm = new TriangleModel("30", "30", "30"); TriangleType testtype = tm.GetTriangleType(tm); Assert.AreEqual(TriangleType.Equilateral.ToString(), testtype.ToString()); }
public Triangle(TriangleType type, T v0, T v1, T v2) { V0 = v0; V1 = v1; V2 = v2; Type = type; }
public TriangleType DetectType() { if (Sides.Length != 3) { throw new InvalidTriangleException(); } int[] s = new int[Sides.Length]; TriangleType result = TriangleType.INVALID; try { for (int i = 0; i < Sides.Length; i++) { s[i] = Sides[i]; } if (s[0] > s[1]) { swap(s, 0, 1); } if (s[0] > s[2]) { swap(s, 0, 2); } if (s[1] > s[2]) { swap(s, 1, 2); } if (s[0] <= 0 || s[2] - s[0] >= s[1]) { throw new InvalidTriangleException(); } if (s[0] == s[2]) { result = TriangleType.EQUILATERAL; } else if (s[0] == s[1] || s[1] == s[2]) { result = TriangleType.ISOSCELES; } else { result = TriangleType.SCALENE; } } catch (Exception e) { result = TriangleType.INVALID; throw e; //re throw } return(result); }
private void StandardBeginPolygon(TriangleType meshType) { _meshType = meshType; _pointTally = 0; _previousToLastIndex = 0; _lastIndex = 0; _fanStartIndex = 0; }
private void StandardBeginPolygon(TriangleType meshType) { _meshType = meshType; _pointTally = 0; _previousToLastIndex = 0; _lastIndex = 0; _fanStartIndex = 0; }
public void ProcessTriangle(int[] sides, TriangleType triangleType) { var stageItem = new TriangleStageItem { Sides = sides, Processed = false, TriangleType = triangleType }; _triangleStageRepository.StageItem(stageItem); }
public Triangle(TriangleType triangleType, double x, double y, double xw, double yw) : base(x, y, xw, yw) { if (triangleType != TriangleType.Triangle45DegPP && triangleType != TriangleType.Triangle45DegPN && triangleType != TriangleType.Triangle45DegNN && triangleType != TriangleType.Triangle45DegNP) throw new InvalidTriangleException(); this.UpdateType(triangleType); }
public void DataDrivenTest() { var a = (double)_testContext.DataRow[0]; //(int)Column.UserId var b = (double)_testContext.DataRow[1]; var c = (double)_testContext.DataRow[2]; TriangleType type = TriangleTester.GetTriangleType(a, b, c); Assert.AreEqual(TriangleType.Equilateral, type); }
public static void Triangle(int offset, int width, int height, TriangleType recType) { for (int i = 0; i < width; i++) { for (int j = 0; j < offset; j++) Console.Write(ReturnAleatoryChar()); switch (recType) { case TriangleType.RectangleLeft: for (int j = 0; j < i; j++) Console.Write("*"); for (int j = 0; j <= width - i; j++) Console.Write(ReturnAleatoryChar()); break; case TriangleType.RectangleRight: for (int j = 0; j < width - i - 1; j++) Console.Write(ReturnAleatoryChar()); for (int j = 0; j < i; j++) Console.Write("*"); break; case TriangleType.Rectangle: for (int j = 0; j < width - i - 1; j++) Console.Write(ReturnAleatoryChar()); for (int j = 0; j < i; j++) Console.Write("*"); for (int j = 0; j < i; j++) Console.Write("*"); for (int j = 0; j < width - i - 1; j++) Console.Write(ReturnAleatoryChar()); break; } Console.WriteLine(); } }
public void BeginPolygon(TriangleType meshType, uint indicesCount) { StandardBeginPolygon(meshType); }
void IXbimTriangulatesToPositionsNormalsIndices.BeginPolygon(TriangleType meshType, uint indicesCount) { StandardBeginPolygon(meshType); }
/// <summary> /// Teiknar þríhyrninga /// </summary> /// <param name="height">Hæð þríhyrningsins</param> /// <param name="TT">Týpan af þríhyrningi</param> /// <param name="s">Strengurinn sem er notaður inní þríhyrningnum</param> /// <param name="p">Strengurinn sem er notaður fyrir utan þríhyrninginn</param> /// <returns>Þríhyrningurinn</returns> /// <example>Triangle(5, TriangleType.Top, "*", " ")</example> public static string Triangle(int height, TriangleType TT, string s = "#", string p = " ") { if (height == 0) return ""; if (height == 1) return s; StringBuilder t = new StringBuilder(); switch (TT) { case TriangleType.TopLeft: { for (int i = height; i >= 0; i--) { for (int a = 0; a < i; a++) { t.Append(s); } t.AppendLine(); } return t.ToString().TrimEnd(); } case TriangleType.BottomLeft: { for (int i = 1; i <= height; i++) { for (int a = 0; a < i; a++) { t.Append(s); } t.AppendLine(); } return t.ToString().TrimEnd(); } case TriangleType.TopRight: { for (int i = height - 1; i >= 0; i--) { for (int a = height - 1; a >= 0; a--) { t.Append(a <= i ? s : p); } t.AppendLine(); } return t.ToString().TrimEnd(); } case TriangleType.BottomRight: { for (int i = 0; i < height; i++) { for (int a = height - 1; a >= 0; a--) { t.Append(a > i ? p : s); } t.AppendLine(); } return t.ToString().TrimEnd(); } case TriangleType.Left: { t.AppendLine(Triangle(height - 1, TriangleType.BottomLeft, s, p)); for (int i = 0; i < height; i++) { t.Append(s); } t.AppendLine().Append(Triangle(height - 1, TriangleType.TopLeft, s, p)); return t.ToString().TrimEnd(); } case TriangleType.Top: { t.Append(Triangle(height - 1, TriangleType.TopRight, s, p)); StringBuilder l = new StringBuilder(); for (int i = 0; i < height; i++) { l.AppendLine(s); } return Tools.MergeStrings(Tools.MergeStrings(t.ToString(), l.ToString().TrimEnd()), Triangle(height - 1, TriangleType.TopLeft, s, p)).TrimEnd(); } case TriangleType.Bottom: { t.Append(Triangle(height - 1, TriangleType.BottomRight, s, p)); StringBuilder l = new StringBuilder(); for (int i = 0; i < height; i++) { l.AppendLine(s); } return Tools.MergeStrings(Tools.MergeStrings(t.Insert(0, "\n").ToString(), l.ToString().TrimEnd()), "\n" + Triangle(height - 1, TriangleType.BottomLeft, s, p)).TrimEnd(); } case TriangleType.Right: { string[] BR = Triangle(height - 1, TriangleType.BottomRight, s, p).Lines(); string[] TR = Triangle(height - 1, TriangleType.TopRight, s, p).Lines(); for (int i = 0; i < BR.Length; i++) { BR[i] = " " + BR[i]; TR[i] = " " + TR[i]; } t.AppendLine(String.Join("\n", BR)); for (int i = 0; i < height; i++) { t.Append(s); } return t.Append("\n" + String.Join("\n", TR)).ToString().TrimEnd(); } } return ""; }
public void BeginPolygon(TriangleType meshType, uint indicesCount) { _sb.AppendFormat("BeginPolygon type: {0} size: {1}\r\n", meshType.ToString(), indicesCount.ToString()); }
public void UpdateType(TriangleType triangleType) { _triangleType = triangleType; switch(_triangleType) { case TriangleType.Triangle45DegPP: _signx = 1; _signy = 1; _p1 = new Point(this.Min.X, this.Min.Y); _p2 = new Point(this.Max.X, this.Min.Y); _p3 = new Point(this.Min.X, this.Max.Y); break; case TriangleType.Triangle45DegPN: _signx = 1; _signy = -1; _p1 = new Point(this.Min.X, this.Min.Y); _p2 = new Point(this.Max.X, this.Max.Y); _p3 = new Point(this.Min.X, this.Max.Y); break; case TriangleType.Triangle45DegNN: _signx = -1; _signy = -1; _p1 = new Point(this.Max.X, this.Min.Y); _p2 = new Point(this.Max.X, this.Max.Y); _p3 = new Point(this.Min.X, this.Max.Y); break; case TriangleType.Triangle45DegNP: _signx = -1; _signy = 1; _p1 = new Point(this.Min.X, this.Min.Y); _p2 = new Point(this.Max.X, this.Min.Y); _p3 = new Point(this.Max.X, this.Max.Y); break; default: throw new InvalidTriangleException(); } _sx = _signx / Math.Sqrt(2); _sy = _signy / Math.Sqrt(2); }