Results 1 to 8 of 8
  1. #1
    robc is offline Member
    Join Date
    Feb 2010
    Posts
    14
    Rep Power
    0

    Default java x,y coordinate

    Can any one help. I trying to shorting up some code.

    I have a jave application that read a floor plan in from CSV file. I getting by (x,y) axis in from the CSV file. Then I do some calculation to find the four points of a fixture, a fixtues is shape like a square. I can have more than one fixture on a floor plan. Once I find all four points I compare to see if two point are touching. The code I have now is about 600 lines long. If you need the code I can upload some of it.

  2. #2
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    lol well we're going to have to see the code if you want us to shorten it. Actually, I don't think anyone is going to shorten it for you, but rather tell you how to shorten it.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  3. #3
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Quote Originally Posted by robc View Post
    I have a jave application that read a floor plan in from CSV file. I getting by (x,y) axis in from the CSV file. Then I do some calculation to find the four points of a fixture, a fixtues is shape like a square. I can have more than one fixture on a floor plan. Once I find all four points I compare to see if two point are touching. The code I have now is about 600 lines long. If you need the code I can upload some of it.
    I could tell you how to shorten it, but my crystal ball has not been working as well as I'd like to lately. It's showing me what I think is your code, but it appears to have been transmutated into Python.

    But seriously, you can't expect anyone to be able to help you based on what you've posted. Please read this link: How To Ask Questions The Smart Way, especially the section on "Be precise and informative about your problem".

    Also, out of curiosity, how many classes does your current program use?

    Suerte!
    Last edited by curmudgeon; 05-29-2010 at 01:18 AM.

  4. #4
    robc is offline Member
    Join Date
    Feb 2010
    Posts
    14
    Rep Power
    0

    Default java x,y coordinate

    here is copy

  5. #5
    robc is offline Member
    Join Date
    Feb 2010
    Posts
    14
    Rep Power
    0

    Default

    /**
    * This method checks between two fixtures whether any two points equals with any two points of another fixture
    * @param fixtureItemX
    * @param fixtureItemY
    * @param fixtureItemX1
    * @param fixtureItemY1
    * @param fixtureItemX2
    * @param fixtureItemY2
    * @param fixtureItemX3
    * @param fixtureItemY3
    * @param referenceInRun_FixtureItemX
    * @param referenceInRun_FixtureItemY
    * @param referenceInRun_FixtureItemX1
    * @param referenceInRun_FixtureItemY1
    * @param referenceInRun_FixtureItemX2
    * @param referenceInRun_FixtureItemY2
    * @param referenceInRun_FixtureItemX3
    * @param referenceInRun_FixtureItemY3
    * @return true or false
    */
    private boolean FourCTwoCompare(int fixtureItemX,int fixtureItemY,int fixtureItemX1,int fixtureItemY1,int fixtureItemX2,int fixtureItemY2,int fixtureItemX3,int fixtureItemY3,
    int referenceInRun_FixtureItemX,int referenceInRun_FixtureItemY,int referenceInRun_FixtureItemX1,int referenceInRun_FixtureItemY1,
    int referenceInRun_FixtureItemX2,int referenceInRun_FixtureItemY2,int referenceInRun_FixtureItemX3,int referenceInRun_FixtureItemY3){
    if((twoPointCompare(fixtureItemX,fixtureItemY,fixt ureItemX1,fixtureItemY1,
    referenceInRun_FixtureItemX,referenceInRun_Fixture ItemY,referenceInRun_FixtureItemX1,referenceInRun_ FixtureItemY1))
    ||(twoPointCompare(fixtureItemX,fixtureItemY,fixtu reItemX1,fixtureItemY1,
    referenceInRun_FixtureItemX,referenceInRun_Fixture ItemY,referenceInRun_FixtureItemX2,referenceInRun_ FixtureItemY2))
    ||(twoPointCompare(fixtureItemX,fixtureItemY,fixtu reItemX1,fixtureItemY1,
    referenceInRun_FixtureItemX,referenceInRun_Fixture ItemY,referenceInRun_FixtureItemX3,referenceInRun_ FixtureItemY3))
    ||(twoPointCompare(fixtureItemX,fixtureItemY,fixtu reItemX1,fixtureItemY1,
    referenceInRun_FixtureItemX1,referenceInRun_Fixtur eItemY1,referenceInRun_FixtureItemX2,referenceInRu n_FixtureItemY2))
    ||(twoPointCompare(fixtureItemX,fixtureItemY,fixtu reItemX1,fixtureItemY1,
    referenceInRun_FixtureItemX1,referenceInRun_Fixtur eItemY1,referenceInRun_FixtureItemX3,referenceInRu n_FixtureItemY3))
    ||(twoPointCompare(fixtureItemX,fixtureItemY,fixtu reItemX1,fixtureItemY1,
    referenceInRun_FixtureItemX2,referenceInRun_Fixtur eItemY2,referenceInRun_FixtureItemX3,referenceInRu n_FixtureItemY3))

    ||(twoPointCompare(fixtureItemX,fixtureItemY,fixtu reItemX2,fixtureItemY2,
    referenceInRun_FixtureItemX,referenceInRun_Fixture ItemY,referenceInRun_FixtureItemX1,referenceInRun_ FixtureItemY1))
    ||(twoPointCompare(fixtureItemX,fixtureItemY,fixtu reItemX2,fixtureItemY2,
    referenceInRun_FixtureItemX,referenceInRun_Fixture ItemY,referenceInRun_FixtureItemX2,referenceInRun_ FixtureItemY2))
    ||(twoPointCompare(fixtureItemX,fixtureItemY,fixtu reItemX2,fixtureItemY2,
    referenceInRun_FixtureItemX,referenceInRun_Fixture ItemY,referenceInRun_FixtureItemX3,referenceInRun_ FixtureItemY3))
    ||(twoPointCompare(fixtureItemX,fixtureItemY,fixtu reItemX2,fixtureItemY2,
    referenceInRun_FixtureItemX1,referenceInRun_Fixtur eItemY1,referenceInRun_FixtureItemX2,referenceInRu n_FixtureItemY2))
    ||(twoPointCompare(fixtureItemX,fixtureItemY,fixtu reItemX2,fixtureItemY2,
    referenceInRun_FixtureItemX1,referenceInRun_Fixtur eItemY1,referenceInRun_FixtureItemX3,referenceInRu n_FixtureItemY3))
    ||(twoPointCompare(fixtureItemX,fixtureItemY,fixtu reItemX2,fixtureItemY2,
    referenceInRun_FixtureItemX2,referenceInRun_Fixtur eItemY2,referenceInRun_FixtureItemX3,referenceInRu n_FixtureItemY3))


    ||(twoPointCompare(fixtureItemX,fixtureItemY,fixtu reItemX3,fixtureItemY3,
    referenceInRun_FixtureItemX,referenceInRun_Fixture ItemY,referenceInRun_FixtureItemX1,referenceInRun_ FixtureItemY1))
    ||(twoPointCompare(fixtureItemX,fixtureItemY,fixtu reItemX3,fixtureItemY3,
    referenceInRun_FixtureItemX,referenceInRun_Fixture ItemY,referenceInRun_FixtureItemX2,referenceInRun_ FixtureItemY2))
    ||(twoPointCompare(fixtureItemX,fixtureItemY,fixtu reItemX3,fixtureItemY3,
    referenceInRun_FixtureItemX,referenceInRun_Fixture ItemY,referenceInRun_FixtureItemX3,referenceInRun_ FixtureItemY3))
    ||(twoPointCompare(fixtureItemX,fixtureItemY,fixtu reItemX3,fixtureItemY3,
    referenceInRun_FixtureItemX1,referenceInRun_Fixtur eItemY1,referenceInRun_FixtureItemX2,referenceInRu n_FixtureItemY2))
    ||(twoPointCompare(fixtureItemX,fixtureItemY,fixtu reItemX3,fixtureItemY3,
    referenceInRun_FixtureItemX1,referenceInRun_Fixtur eItemY1,referenceInRun_FixtureItemX3,referenceInRu n_FixtureItemY3))
    ||(twoPointCompare(fixtureItemX,fixtureItemY,fixtu reItemX3,fixtureItemY3,
    referenceInRun_FixtureItemX2,referenceInRun_Fixtur eItemY2,referenceInRun_FixtureItemX3,referenceInRu n_FixtureItemY3))

    ||(twoPointCompare(fixtureItemX1,fixtureItemY1,fix tureItemX2,fixtureItemY2,
    referenceInRun_FixtureItemX,referenceInRun_Fixture ItemY,referenceInRun_FixtureItemX1,referenceInRun_ FixtureItemY1))
    ||(twoPointCompare(fixtureItemX1,fixtureItemY1,fix tureItemX2,fixtureItemY2,
    referenceInRun_FixtureItemX,referenceInRun_Fixture ItemY,referenceInRun_FixtureItemX2,referenceInRun_ FixtureItemY2))
    ||(twoPointCompare(fixtureItemX1,fixtureItemY1,fix tureItemX2,fixtureItemY2,
    referenceInRun_FixtureItemX,referenceInRun_Fixture ItemY,referenceInRun_FixtureItemX3,referenceInRun_ FixtureItemY3))
    ||(twoPointCompare(fixtureItemX1,fixtureItemY1,fix tureItemX2,fixtureItemY2,
    referenceInRun_FixtureItemX1,referenceInRun_Fixtur eItemY1,referenceInRun_FixtureItemX2,referenceInRu n_FixtureItemY2))
    ||(twoPointCompare(fixtureItemX1,fixtureItemY1,fix tureItemX2,fixtureItemY2,
    referenceInRun_FixtureItemX1,referenceInRun_Fixtur eItemY1,referenceInRun_FixtureItemX3,referenceInRu n_FixtureItemY3))
    ||(twoPointCompare(fixtureItemX1,fixtureItemY1,fix tureItemX2,fixtureItemY2,
    referenceInRun_FixtureItemX2,referenceInRun_Fixtur eItemY2,referenceInRun_FixtureItemX3,referenceInRu n_FixtureItemY3))

    ||(twoPointCompare(fixtureItemX1,fixtureItemY1,fix tureItemX3,fixtureItemY3,
    referenceInRun_FixtureItemX,referenceInRun_Fixture ItemY,referenceInRun_FixtureItemX1,referenceInRun_ FixtureItemY1))
    ||(twoPointCompare(fixtureItemX1,fixtureItemY1,fix tureItemX3,fixtureItemY3,
    referenceInRun_FixtureItemX,referenceInRun_Fixture ItemY,referenceInRun_FixtureItemX2,referenceInRun_ FixtureItemY2))
    ||(twoPointCompare(fixtureItemX1,fixtureItemY1,fix tureItemX3,fixtureItemY3,
    referenceInRun_FixtureItemX,referenceInRun_Fixture ItemY,referenceInRun_FixtureItemX3,referenceInRun_ FixtureItemY3))
    ||(twoPointCompare(fixtureItemX1,fixtureItemY1,fix tureItemX3,fixtureItemY3,
    referenceInRun_FixtureItemX1,referenceInRun_Fixtur eItemY1,referenceInRun_FixtureItemX2,referenceInRu n_FixtureItemY2))
    ||(twoPointCompare(fixtureItemX1,fixtureItemY1,fix tureItemX3,fixtureItemY3,
    referenceInRun_FixtureItemX1,referenceInRun_Fixtur eItemY1,referenceInRun_FixtureItemX3,referenceInRu n_FixtureItemY3))
    ||(twoPointCompare(fixtureItemX1,fixtureItemY1,fix tureItemX3,fixtureItemY3,
    referenceInRun_FixtureItemX2,referenceInRun_Fixtur eItemY2,referenceInRun_FixtureItemX3,referenceInRu n_FixtureItemY3))


    ||(twoPointCompare(fixtureItemX2,fixtureItemY2,fix tureItemX3,fixtureItemY3,
    referenceInRun_FixtureItemX,referenceInRun_Fixture ItemY,referenceInRun_FixtureItemX1,referenceInRun_ FixtureItemY1))
    ||(twoPointCompare(fixtureItemX2,fixtureItemY2,fix tureItemX3,fixtureItemY3,
    referenceInRun_FixtureItemX,referenceInRun_Fixture ItemY,referenceInRun_FixtureItemX2,referenceInRun_ FixtureItemY2))
    ||(twoPointCompare(fixtureItemX2,fixtureItemY2,fix tureItemX3,fixtureItemY3,
    referenceInRun_FixtureItemX,referenceInRun_Fixture ItemY,referenceInRun_FixtureItemX3,referenceInRun_ FixtureItemY3))
    ||(twoPointCompare(fixtureItemX2,fixtureItemY2,fix tureItemX3,fixtureItemY3,
    referenceInRun_FixtureItemX1,referenceInRun_Fixtur eItemY1,referenceInRun_FixtureItemX2,referenceInRu n_FixtureItemY2))
    ||(twoPointCompare(fixtureItemX2,fixtureItemY2,fix tureItemX3,fixtureItemY3,
    referenceInRun_FixtureItemX1,referenceInRun_Fixtur eItemY1,referenceInRun_FixtureItemX3,referenceInRu n_FixtureItemY3))
    ||(twoPointCompare(fixtureItemX2,fixtureItemY2,fix tureItemX3,fixtureItemY3,
    referenceInRun_FixtureItemX2,referenceInRun_Fixtur eItemY2,referenceInRun_FixtureItemX3,referenceInRu n_FixtureItemY3))


    ){
    return true;
    }
    else{
    return false;
    }

    }

  6. #6
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Recommendation 1: read up on and use arrays. Then use nested for loops to iterate through both sets of arrays.

    edit: also, (again) how many classes does this project use?

    By using arrays and refactoring your code into its necessary constituent classes, you can often greatly reduce code redudancy.
    Last edited by curmudgeon; 05-29-2010 at 04:51 AM.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Also, please learn to use code tags when posting code in the forum. Which is easier to read in the forum, your un-tagged code above or this?

    Java Code:
      private boolean FourCTwoCompare(int fixtureItemX, int fixtureItemY, int fixtureItemX1,
          int fixtureItemY1, int fixtureItemX2, int fixtureItemY2, int fixtureItemX3,
          int fixtureItemY3, int referenceInRun_FixtureItemX, int referenceInRun_FixtureItemY,
          int referenceInRun_FixtureItemX1, int referenceInRun_FixtureItemY1,
          int referenceInRun_FixtureItemX2, int referenceInRun_FixtureItemY2,
          int referenceInRun_FixtureItemX3, int referenceInRun_FixtureItemY3) {
        if ((twoPointCompare(fixtureItemX, fixtureItemY, fixtureItemX1, fixtureItemY1,
            referenceInRun_FixtureItemX, referenceInRun_FixtureItemY, referenceInRun_FixtureItemX1,
            referenceInRun_FixtureItemY1))
            || (twoPointCompare(fixtureItemX, fixtureItemY, fixtureItemX1, fixtureItemY1,
                referenceInRun_FixtureItemX, referenceInRun_FixtureItemY, referenceInRun_FixtureItemX2,
                referenceInRun_FixtureItemY2))
            || (twoPointCompare(fixtureItemX, fixtureItemY, fixtureItemX1, fixtureItemY1,
                referenceInRun_FixtureItemX, referenceInRun_FixtureItemY, referenceInRun_FixtureItemX3,
                referenceInRun_FixtureItemY3))
            || (twoPointCompare(fixtureItemX, fixtureItemY, fixtureItemX1, fixtureItemY1,
                referenceInRun_FixtureItemX1, referenceInRun_FixtureItemY1,
                referenceInRun_FixtureItemX2, referenceInRun_FixtureItemY2))
            || (twoPointCompare(fixtureItemX, fixtureItemY, fixtureItemX1, fixtureItemY1,
                referenceInRun_FixtureItemX1, referenceInRun_FixtureItemY1,
                referenceInRun_FixtureItemX3, referenceInRun_FixtureItemY3))
            || (twoPointCompare(fixtureItemX, fixtureItemY, fixtureItemX1, fixtureItemY1,
                referenceInRun_FixtureItemX2, referenceInRun_FixtureItemY2,
                referenceInRun_FixtureItemX3, referenceInRun_FixtureItemY3))
    
            || (twoPointCompare(fixtureItemX, fixtureItemY, fixtureItemX2, fixtureItemY2,
                referenceInRun_FixtureItemX, referenceInRun_FixtureItemY, referenceInRun_FixtureItemX1,
                referenceInRun_FixtureItemY1))
            || (twoPointCompare(fixtureItemX, fixtureItemY, fixtureItemX2, fixtureItemY2,
                referenceInRun_FixtureItemX, referenceInRun_FixtureItemY, referenceInRun_FixtureItemX2,
                referenceInRun_FixtureItemY2))
            || (twoPointCompare(fixtureItemX, fixtureItemY, fixtureItemX2, fixtureItemY2,
                referenceInRun_FixtureItemX, referenceInRun_FixtureItemY, referenceInRun_FixtureItemX3,
                referenceInRun_FixtureItemY3))
            || (twoPointCompare(fixtureItemX, fixtureItemY, fixtureItemX2, fixtureItemY2,
                referenceInRun_FixtureItemX1, referenceInRun_FixtureItemY1,
                referenceInRun_FixtureItemX2, referenceInRun_FixtureItemY2))
            || (twoPointCompare(fixtureItemX, fixtureItemY, fixtureItemX2, fixtureItemY2,
                referenceInRun_FixtureItemX1, referenceInRun_FixtureItemY1,
                referenceInRun_FixtureItemX3, referenceInRun_FixtureItemY3))
            || (twoPointCompare(fixtureItemX, fixtureItemY, fixtureItemX2, fixtureItemY2,
                referenceInRun_FixtureItemX2, referenceInRun_FixtureItemY2,
                referenceInRun_FixtureItemX3, referenceInRun_FixtureItemY3))
    
            || (twoPointCompare(fixtureItemX, fixtureItemY, fixtureItemX3, fixtureItemY3,
                referenceInRun_FixtureItemX, referenceInRun_FixtureItemY, referenceInRun_FixtureItemX1,
                referenceInRun_FixtureItemY1))
            || (twoPointCompare(fixtureItemX, fixtureItemY, fixtureItemX3, fixtureItemY3,
                referenceInRun_FixtureItemX, referenceInRun_FixtureItemY, referenceInRun_FixtureItemX2,
                referenceInRun_FixtureItemY2))
            || (twoPointCompare(fixtureItemX, fixtureItemY, fixtureItemX3, fixtureItemY3,
                referenceInRun_FixtureItemX, referenceInRun_FixtureItemY, referenceInRun_FixtureItemX3,
                referenceInRun_FixtureItemY3))
            || (twoPointCompare(fixtureItemX, fixtureItemY, fixtureItemX3, fixtureItemY3,
                referenceInRun_FixtureItemX1, referenceInRun_FixtureItemY1,
                referenceInRun_FixtureItemX2, referenceInRun_FixtureItemY2))
            || (twoPointCompare(fixtureItemX, fixtureItemY, fixtureItemX3, fixtureItemY3,
                referenceInRun_FixtureItemX1, referenceInRun_FixtureItemY1,
                referenceInRun_FixtureItemX3, referenceInRun_FixtureItemY3))
            || (twoPointCompare(fixtureItemX, fixtureItemY, fixtureItemX3, fixtureItemY3,
                referenceInRun_FixtureItemX2, referenceInRun_FixtureItemY2,
                referenceInRun_FixtureItemX3, referenceInRun_FixtureItemY3))
    
            || (twoPointCompare(fixtureItemX1, fixtureItemY1, fixtureItemX2, fixtureItemY2,
                referenceInRun_FixtureItemX, referenceInRun_FixtureItemY, referenceInRun_FixtureItemX1,
                referenceInRun_FixtureItemY1))
            || (twoPointCompare(fixtureItemX1, fixtureItemY1, fixtureItemX2, fixtureItemY2,
                referenceInRun_FixtureItemX, referenceInRun_FixtureItemY, referenceInRun_FixtureItemX2,
                referenceInRun_FixtureItemY2))
            || (twoPointCompare(fixtureItemX1, fixtureItemY1, fixtureItemX2, fixtureItemY2,
                referenceInRun_FixtureItemX, referenceInRun_FixtureItemY, referenceInRun_FixtureItemX3,
                referenceInRun_FixtureItemY3))
            || (twoPointCompare(fixtureItemX1, fixtureItemY1, fixtureItemX2, fixtureItemY2,
                referenceInRun_FixtureItemX1, referenceInRun_FixtureItemY1,
                referenceInRun_FixtureItemX2, referenceInRun_FixtureItemY2))
            || (twoPointCompare(fixtureItemX1, fixtureItemY1, fixtureItemX2, fixtureItemY2,
                referenceInRun_FixtureItemX1, referenceInRun_FixtureItemY1,
                referenceInRun_FixtureItemX3, referenceInRun_FixtureItemY3))
            || (twoPointCompare(fixtureItemX1, fixtureItemY1, fixtureItemX2, fixtureItemY2,
                referenceInRun_FixtureItemX2, referenceInRun_FixtureItemY2,
                referenceInRun_FixtureItemX3, referenceInRun_FixtureItemY3))
    
            || (twoPointCompare(fixtureItemX1, fixtureItemY1, fixtureItemX3, fixtureItemY3,
                referenceInRun_FixtureItemX, referenceInRun_FixtureItemY, referenceInRun_FixtureItemX1,
                referenceInRun_FixtureItemY1))
            || (twoPointCompare(fixtureItemX1, fixtureItemY1, fixtureItemX3, fixtureItemY3,
                referenceInRun_FixtureItemX, referenceInRun_FixtureItemY, referenceInRun_FixtureItemX2,
                referenceInRun_FixtureItemY2))
            || (twoPointCompare(fixtureItemX1, fixtureItemY1, fixtureItemX3, fixtureItemY3,
                referenceInRun_FixtureItemX, referenceInRun_FixtureItemY, referenceInRun_FixtureItemX3,
                referenceInRun_FixtureItemY3))
            || (twoPointCompare(fixtureItemX1, fixtureItemY1, fixtureItemX3, fixtureItemY3,
                referenceInRun_FixtureItemX1, referenceInRun_FixtureItemY1,
                referenceInRun_FixtureItemX2, referenceInRun_FixtureItemY2))
            || (twoPointCompare(fixtureItemX1, fixtureItemY1, fixtureItemX3, fixtureItemY3,
                referenceInRun_FixtureItemX1, referenceInRun_FixtureItemY1,
                referenceInRun_FixtureItemX3, referenceInRun_FixtureItemY3))
            || (twoPointCompare(fixtureItemX1, fixtureItemY1, fixtureItemX3, fixtureItemY3,
                referenceInRun_FixtureItemX2, referenceInRun_FixtureItemY2,
                referenceInRun_FixtureItemX3, referenceInRun_FixtureItemY3))
    
            || (twoPointCompare(fixtureItemX2, fixtureItemY2, fixtureItemX3, fixtureItemY3,
                referenceInRun_FixtureItemX, referenceInRun_FixtureItemY, referenceInRun_FixtureItemX1,
                referenceInRun_FixtureItemY1))
            || (twoPointCompare(fixtureItemX2, fixtureItemY2, fixtureItemX3, fixtureItemY3,
                referenceInRun_FixtureItemX, referenceInRun_FixtureItemY, referenceInRun_FixtureItemX2,
                referenceInRun_FixtureItemY2))
            || (twoPointCompare(fixtureItemX2, fixtureItemY2, fixtureItemX3, fixtureItemY3,
                referenceInRun_FixtureItemX, referenceInRun_FixtureItemY, referenceInRun_FixtureItemX3,
                referenceInRun_FixtureItemY3))
            || (twoPointCompare(fixtureItemX2, fixtureItemY2, fixtureItemX3, fixtureItemY3,
                referenceInRun_FixtureItemX1, referenceInRun_FixtureItemY1,
                referenceInRun_FixtureItemX2, referenceInRun_FixtureItemY2))
            || (twoPointCompare(fixtureItemX2, fixtureItemY2, fixtureItemX3, fixtureItemY3,
                referenceInRun_FixtureItemX1, referenceInRun_FixtureItemY1,
                referenceInRun_FixtureItemX3, referenceInRun_FixtureItemY3))
            || (twoPointCompare(fixtureItemX2, fixtureItemY2, fixtureItemX3, fixtureItemY3,
                referenceInRun_FixtureItemX2, referenceInRun_FixtureItemY2,
                referenceInRun_FixtureItemX3, referenceInRun_FixtureItemY3))
    
        ) {
          return true;
        } else {
          return false;
        }
    
      }
    OK, bad example as they're both pretty hard to read, but still, in most cases tags help.

    To use tags, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.

    Another way to do this is to manually place the tags into your code by placing the tag [code] above your pasted code and the tag [/code] below your pasted code like so:

    Java Code:
    [code]
      // your code goes here
      // notice how the top and bottom tags are different
    [/code]
    Best of luck!

  8. #8
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    We can make it much more readable just by shortening the variable names, and getting rid of all the ||s:
    Java Code:
    private boolean FourCTwoCompare(int a0X, int a0Y, int a1X, int a1Y, int a2X, int a2Y, int a3X, int a3Y,
                                    int b0x, int b0Y, int b1X, int b1Y, int b2X, int b2Y, int b3X, int b3Y) {
            if (twoPointCompare(a0X, a0Y, a1X, a1Y, b0X, b0Y, b1X, b1Y)) return true;
            if (twoPointCompare(a0X, a0Y, a1X, a1Y, b0X, b0Y, b2X, b2Y)) return true;
            if (twoPointCompare(a0X, a0Y, a1X, a1Y, b0X, b0Y, b3X, b3Y)) return true;
            if (twoPointCompare(a0X, a0Y, a1X, a1Y, b1X, b1Y, b2X, b2Y)) return true;
            if (twoPointCompare(a0X, a0Y, a1X, a1Y, b1X, b1Y, b3X, b3Y)) return true;
            if (twoPointCompare(a0X, a0Y, a1X, a1Y, b2X, b2Y, b3X, b3Y)) return true;
    
            if (twoPointCompare(a0X, a0Y, a2X, a2Y, b0X, b0Y, b1X, b1Y)) return true;
            if (twoPointCompare(a0X, a0Y, a2X, a2Y, b0X, b0Y, b2X, b2Y)) return true;
            if (twoPointCompare(a0X, a0Y, a2X, a2Y, b0X, b0Y, b3X, b3Y)) return true;
            if (twoPointCompare(a0X, a0Y, a2X, a2Y, b1X, b1Y, b2X, b2Y)) return true;
            if (twoPointCompare(a0X, a0Y, a2X, a2Y, b1X, b1Y, b3X, b3Y)) return true;
            if (twoPointCompare(a0X, a0Y, a2X, a2Y, b2X, b2Y, b3X, b3Y)) return true;
    
            if (twoPointCompare(a0X, a0Y, a3X, a3Y, b0X, b0Y, b1X, b1Y)) return true;
            if (twoPointCompare(a0X, a0Y, a3X, a3Y, b0X, b0Y, b2X, b2Y)) return true;
            if (twoPointCompare(a0X, a0Y, a3X, a3Y, b0X, b0Y, b3X, b3Y)) return true;
            if (twoPointCompare(a0X, a0Y, a3X, a3Y, b1X, b1Y, b2X, b2Y)) return true;
            if (twoPointCompare(a0X, a0Y, a3X, a3Y, b1X, b1Y, b3X, b3Y)) return true;
            if (twoPointCompare(a0X, a0Y, a3X, a3Y, b2X, b2Y, b3X, b3Y)) return true;
    
            if (twoPointCompare(a1X, a1Y, a2X, a2Y, b0X, b0Y, b1X, b1Y)) return true;
            if (twoPointCompare(a1X, a1Y, a2X, a2Y, b0X, b0Y, b2X, b2Y)) return true;
            if (twoPointCompare(a1X, a1Y, a2X, a2Y, b0X, b0Y, b3X, b3Y)) return true;
            if (twoPointCompare(a1X, a1Y, a2X, a2Y, b1X, b1Y, b2X, b2Y)) return true;
            if (twoPointCompare(a1X, a1Y, a2X, a2Y, b1X, b1Y, b3X, b3Y)) return true;
            if (twoPointCompare(a1X, a1Y, a2X, a2Y, b2X, b2Y, b3X, b3Y)) return true;
    
            if (twoPointCompare(a1X, a1Y, a3X, a3Y, b0X, b0Y, b1X, b1Y)) return true;
            if (twoPointCompare(a1X, a1Y, a3X, a3Y, b0X, b0Y, b2X, b2Y)) return true;
            if (twoPointCompare(a1X, a1Y, a3X, a3Y, b0X, b0Y, b3X, b3Y)) return true;
            if (twoPointCompare(a1X, a1Y, a3X, a3Y, b1X, b1Y, b2X, b2Y)) return true;
            if (twoPointCompare(a1X, a1Y, a3X, a3Y, b1X, b1Y, b3X, b3Y)) return true;
            if (twoPointCompare(a1X, a1Y, a3X, a3Y, b2X, b2Y, b3X, b3Y)) return true;
    
            if (twoPointCompare(a2X, a2Y, a3X, a3Y, b0X, b0Y, b1X, b1Y)) return true;
            if (twoPointCompare(a2X, a2Y, a3X, a3Y, b0X, b0Y, b2X, b2Y)) return true;
            if (twoPointCompare(a2X, a2Y, a3X, a3Y, b0X, b0Y, b3X, b3Y)) return true;
            if (twoPointCompare(a2X, a2Y, a3X, a3Y, b1X, b1Y, b2X, b2Y)) return true;
            if (twoPointCompare(a2X, a2Y, a3X, a3Y, b1X, b1Y, b3X, b3Y)) return true;
            if (twoPointCompare(a2X, a2Y, a3X, a3Y, b2X, b2Y, b3X, b3Y)) return true;
            return false;
    }
    We can do a little better than that with some arrays and looping:
    Java Code:
    private boolean FourCTwoCompare(int[] aX, int[] aY, int[] bX, int[] bY) {
            // assumes the X and Y arrays are the same length
            for (int i = 0; i < aX.length - 1; i++) {
                    for (int j = i + 1; j < aX.length; j++) {
                            for (int m = 0; m < bX.length - 1; m++) {
                                    for (int n = m + 1; n < bX.length; n++) {
                                            if (twoPointCompare(aX[i], aY[i], aX[j], aY[j], bX[m], bY[m], bX[n], bY[n]) return true;
                                    }
                            }
                    }
            }
            return false;
    }
    That's still rather ugly, and this sort of thing is precisely why object-oriented programming was conceived. What you'd really like to do is something more like this:
    Java Code:
    public class Fixture {
            private Point[] corners;
    
            ...
    
            public boolean overlaps(Fixture other) {
                    ...
            }
    }
    -Gary-

Similar Threads

  1. Replies: 3
    Last Post: 02-07-2010, 08:34 PM
  2. Replies: 3
    Last Post: 12-15-2009, 09:20 PM
  3. Replies: 4
    Last Post: 12-17-2008, 05:57 PM
  4. set coordinate to an image
    By nuur in forum AWT / Swing
    Replies: 2
    Last Post: 04-01-2008, 08:08 AM
  5. X&Y Coordinate Drawing on jPanel
    By BHCluster in forum Java 2D
    Replies: 2
    Last Post: 03-27-2008, 10:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •