fork download
  1. Option Explicit On
  2. Option Strict On
  3. Option Compare Binary
  4. Option Infer On
  5.  
  6. Imports System.Collections.Generic
  7. Imports System.Numerics
  8. Imports Tp = System.Tuple(Of Integer, Integer)
  9.  
  10. Public Class CheckPolygon
  11. Private Class Point
  12. Public ReadOnly x, y As BigInteger
  13. Sub New (x As Integer, y As Integer)
  14. Me.x = x: Me.y = y
  15. End Sub
  16. Function Gaiseki(p1 As Point, p2 As Point) As BigInteger
  17. Dim a As BigInteger = (p1.x - Me.x) * (p2.y - Me.y)
  18. Dim b As BigInteger = (p1.y - Me.y) * (p2.x - Me.x)
  19. Gaiseki = a - b
  20. End Function
  21. End Class
  22. Private Class Line
  23. Public ReadOnly p1, p2 As Point
  24. Public ReadOnly dx, dy As BigInteger
  25. Sub New (p1 As Point, p2 As Point)
  26. Me.p1 = p1: Me.p2 = p2
  27. Me.dx = p2.x - p1.x
  28. Me.dy = p2.y - p1.y
  29. End Sub
  30. Function IsPara(other As Line) As Boolean
  31. If Me.dx = 0 Then
  32. IsPara = other.dx = 0
  33. ElseIf other.dx = 0 Then
  34. IsPara = Me.dx = 0
  35. ElseIf Me.dy = 0 Then
  36. IsPara = other.dy = 0
  37. ElseIf other.dy = 0 Then
  38. IsPara = Me.dy = 0
  39. Else
  40. Dim a As BigInteger = Me.dx * other.dy
  41. Dim b As BigInteger = Me.dy * other.dx
  42. IsPara = a - b = 0
  43. End If
  44. End Function
  45. Function IsIntersect(other As Line) As Boolean
  46. IsIntersect = False
  47. If IsPara(other) Then Exit Function
  48. Dim a As BigInteger = Me.p1.Gaiseki(Me.p2, other.p1)
  49. Dim b As BigInteger = Me.p1.Gaiseki(Me.p2, other.p2)
  50. Dim c As BigInteger = other.p1.Gaiseki(other.p2, Me.p1)
  51. Dim d As BigInteger = other.p1.Gaiseki(other.p2, Me.p2)
  52. IsIntersect = a * b <= 0 AndAlso c * d <= 0
  53. End Function
  54. End Class
  55. Public Function check(X As Integer(), Y As Integer()) As String
  56. check = "Not simple"
  57. Dim N As Integer = X.Length
  58. Dim lines(N) As Line
  59. Dim hs As New HashSet(Of Tp)()
  60. For i As Integer = 0 To N - 1
  61. Dim t As New Tp(X(i), Y(i))
  62. If Not hs.Add(t) Then Exit Function
  63. Next i
  64. For i As Integer = 0 To N - 2
  65. Dim p1 As New Point(X(i), Y(i))
  66. Dim p2 As New Point(X(i+1), Y(i+1))
  67. lines(i) = New Line(p1, p2)
  68. If lines(i).dx = 0 AndAlso lines(i).dy = 0 Then Exit Function
  69. Next i
  70. lines(N - 1) = New Line(New Point(X(N-1),Y(N-1)), New Point(X(0),Y(0)))
  71. lines(N) = lines(0)
  72. For i As Integer = 0 To N - 1
  73. If lines(i).IsPara(lines(i+1)) Then Exit Function
  74. Next i
  75. For i As Integer = 0 To N
  76. For j As Integer = 0 To N
  77. If Math.Abs(j - i) <= 1 Then Continue For
  78. If Math.Abs(j - i) >= N - 1 Then Continue For
  79. If lines(i).IsIntersect(lines(j)) Then
  80. Console.WriteLine("intersect {0} {1}", i, j)
  81. Console.WriteLine("({0}, {1}) - ({2}, {3})", lines(i).p1.x, lines(i).p1.y, lines(i).p2.x, lines(i).p2.y)
  82. Console.WriteLine("({0}, {1}) - ({2}, {3})", lines(j).p1.x, lines(j).p1.y, lines(j).p2.x, lines(j).p2.y)
  83. Exit Function
  84. End If
  85. Next j
  86. Next i
  87. Dim ret As BigInteger = 0
  88. For i As Integer = 0 To N - 1
  89. Dim ln As Line = lines(i)
  90. ret += ln.p1.x * ln.p2.y - ln.p1.y * ln.p2.x
  91. Next i
  92. If ret < 0 Then ret = -ret
  93. check = String.Format("{0:F01}", CDbl(ret) / 2.0)
  94. End Function
  95. End Class
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Visual Basic.Net Compiler version 0.0.0.5943 (Mono 4.0.1 - tarball)
Copyright (C) 2004-2010 Rolf Bjarne Kvinge. All rights reserved.

/home/sz6qsb/prog.vb (8,38) : error VBNC99999: vbnc crashed nearby this location in the source code.
vbnc : Command line : error VBNC99999: Unexpected error: Object reference not set to an instance of an object
  at vbnc.Parser.ParseList[T] (vbnc.BaseList`1[T] List, vbnc.Parser+ParseDelegate_Parent`1[T] ParseMethod, vbnc.ParsedObject Parent) [0x0003f] in <d77f4191aaaa4ed9a9a36d67dd32844d>:0 
  at vbnc.Parser.ParseConstructedTypeName (vbnc.ParsedObject Parent) [0x0009b] in <d77f4191aaaa4ed9a9a36d67dd32844d>:0 
  at vbnc.Parser.ParseImportsNamespaceClause (vbnc.ParsedObject Parent) [0x000c7] in <d77f4191aaaa4ed9a9a36d67dd32844d>:0 
  at vbnc.Parser.ParseImportsAliasClause (vbnc.ParsedObject Parent) [0x00058] in <d77f4191aaaa4ed9a9a36d67dd32844d>:0 
  at vbnc.Parser.ParseImportsClause (vbnc.ParsedObject Parent) [0x0001e] in <d77f4191aaaa4ed9a9a36d67dd32844d>:0 
  at vbnc.Parser.ParseList[T] (vbnc.BaseList`1[T] List, vbnc.Parser+ParseDelegate_Parent`1[T] ParseMethod, vbnc.ParsedObject Parent) [0x00005] in <d77f4191aaaa4ed9a9a36d67dd32844d>:0 
  at vbnc.Parser.ParseImportsClauses (vbnc.ImportsStatement Parent) [0x0000c] in <d77f4191aaaa4ed9a9a36d67dd32844d>:0 
  at vbnc.Parser.ParseImportsStatement (vbnc.ParsedObject Parent) [0x0001b] in <d77f4191aaaa4ed9a9a36d67dd32844d>:0 
  at vbnc.Parser.ParseImportsStatements (vbnc.ParsedObject Parent) [0x0001e] in <d77f4191aaaa4ed9a9a36d67dd32844d>:0 
  at vbnc.Parser.ParseFileHeader (vbnc.CodeFile CodeFile, vbnc.AssemblyDeclaration Assembly) [0x003b0] in <d77f4191aaaa4ed9a9a36d67dd32844d>:0 
  at vbnc.Parser.ParseAssemblyDeclaration (System.String RootNamespace, vbnc.AssemblyDeclaration assembly) [0x00089] in <d77f4191aaaa4ed9a9a36d67dd32844d>:0 
  at vbnc.Parser.Parse (System.String RootNamespace, vbnc.AssemblyDeclaration assembly) [0x00007] in <d77f4191aaaa4ed9a9a36d67dd32844d>:0 
  at vbnc.Compiler.Compile_Parse () [0x0008b] in <d77f4191aaaa4ed9a9a36d67dd32844d>:0 
Compilation took 00:00:00.6970110
stdout
Standard output is empty