0

I am having the issue of my greater than/less than comparison not working.

Here is what is happening:

Let's say I have a square, and I'm getting the minimum and maximum points of this square in space, ex. minPoint = (0,0,0) and maxPoint = (1,1,1)

I am placing text on this face but I need the text to be inside the square face, if it isn't then I reduce the size until it fits.

Here is my code after properly getting the distance of both the minPt to the maxPt, and also the minPt to the text location.

Here is my line of code that is not working:

If sizeYPt <= sizeY And sizeXPt <= sizeX Then Exit Do

It works for most situations but I have had situations where it won't work. One thing I noticed is that sizeYPt is the same as sizeY, and sizeXPt is smaller than sizeX (which should all be true!!! argh)

Anyone know what the issue could be? Here is my full code:

Dim sizeY, sizeX, sizeYPt, sizeXPt As Double
Dim yVect, xVect As New VISIVector

yVect.Put(0, 1, 0)
xVect.Put(1, 0, 0)

sizeY = Util.dist2pts_alongAxis(centerPoint, p2, yVect)
sizeYPt = Util.dist2pts_alongAxis(centerPoint, txtPt, yVect)
sizeX = Util.dist2pts_alongAxis(p1, p2, xVect)
sizeXPt = Util.dist2pts_alongAxis(p1, txtPt, xVect)

If sizeY.ToString.Contains("-") Then sizeY = sizeY * -1
If sizeYPt.ToString.Contains("-") Then sizeYPt = sizeYPt * -1
If sizeX.ToString.Contains("-") Then sizeX = sizeX * -1
If sizeXPt.ToString.Contains("-") Then sizeXPt = sizeXPt * -1

MsgBox(sizeYPt & " | " & sizeY & vbNewLine & sizeXPt & " | " & sizeX)

If sizeYPt <= sizeY And sizeXPt <= sizeX Then Exit Do
Joe
  • 128
  • 1
  • 11
  • 1
    Perhaps post the rest of the code? As it is, this isn't a valid loop. – Overt_Agent Mar 18 '15 at 15:19
  • To summarize this up, sizeXPt is coming out less than sizeX but it is still not returning true... @niallmcfc the rest of my code is not necessary to see. :P – Joe Mar 18 '15 at 15:19
  • Could be a "problem" with the double values, maybe this can help: http://stackoverflow.com/questions/1398753/comparing-double-values-in-c-sharp – David Sdot Mar 18 '15 at 15:22
  • 2
    Floating point math is inexact, you need a "close enough" check. Use, say, If SizeYPt - SizeY <= 1E-12 – Hans Passant Mar 18 '15 at 15:22
  • @HansPassant That is the solution! Thank you so much, please answer this so you get the credit. :) – Joe Mar 18 '15 at 15:31

1 Answers1

0

Floating point math is inexact, you need a "close enough" check. Use, say, If SizeYPt - SizeY <= 1E-12

Joe
  • 128
  • 1
  • 11