Package org.gbcpainter.game.model.grid

Examples of org.gbcpainter.game.model.grid.Junction


    }

    final Map<Segment, Pipe> segmentToPipe = new HashMap<>( levelMap.edgeSet().size() );

    for (Segment edge : levelMap.edgeSet()) {
      Junction vertexA = pointToJunction.get( levelMap.getEdgeSource( edge ) );
      Junction vertexB = pointToJunction.get( levelMap.getEdgeTarget( edge ) );
      segmentToPipe.put( edge, pipeGrid.addEdge( vertexA, vertexB ) );
    }

    final Map<Set<Pipe>, Integer> faceMap = new HashMap<>( rawFacesMap.size() );
View Full Code Here


    assertTrue( pipe.isColored() );
  }

  @Test
  public void testJunctionColoring() throws Exception {
    Junction junction = new JunctionImpl( new Point( 0, 0 ), new HashSet<>(
        Arrays.asList( PERPENDICULAR_DIRECTION.LEFT, PERPENDICULAR_DIRECTION.RIGHT, PERPENDICULAR_DIRECTION.DOWN )
    ) );

    assertFalse( junction.isColored() );

    junction.setColored( true );
    assertTrue( junction.isColored() );


    junction.setColored( false );
    assertFalse( junction.isColored() );
  }
View Full Code Here

    assertEquals( pipe.getAvailableDirections(), new HashSet<>( Arrays.asList( PERPENDICULAR_DIRECTION.UP, PERPENDICULAR_DIRECTION.DOWN ) ) );
  }

  @Test
  public void junctionHitTest() throws Exception {
    Junction junction = new JunctionImpl( new Point( 0, 0 ), new HashSet<>(
        Arrays.asList( PERPENDICULAR_DIRECTION.LEFT, PERPENDICULAR_DIRECTION.RIGHT, PERPENDICULAR_DIRECTION.DOWN )
    ) );

    assertTrue( junction.contains( new Point( 0, 0 ) ) );

    assertFalse( junction.contains( new Point( 1, 0 ) ) );
    assertFalse( junction.contains( new Point( 0, 1 ) ) );

    assertEquals( junction.getAvailableDirections(), new HashSet<>( Arrays.asList( PERPENDICULAR_DIRECTION.LEFT, PERPENDICULAR_DIRECTION.RIGHT,
                                                                                   PERPENDICULAR_DIRECTION.DOWN ) ) );
  }
View Full Code Here

            throw new AssertionError( "Invalid enum value " + direction );
        }

        if ( isCandidate ) {
          if ( edge.isVoidPipe() ) {
            final Junction otherJunction = graph.getEdgeSource( edge );
            return otherJunction.getPosition()
                                .equals( ( (Junction) element ).getPosition() ) ? graph
                       .getEdgeTarget(
                           edge ) : otherJunction;
          } else {
            return edge;
          }
        }
      }

      throw new NoSuchElementException( "Can't find a valid element in that direction" );
    } else if ( element instanceof Pipe ) {
      /* PIPE */
      final Junction firstElement = graph.getEdgeSource( (Pipe) element );
      final Junction secondElement = graph.getEdgeTarget( (Pipe) element );
      final Point firstPosition = firstElement.getPosition();
      final Point secondPosition = secondElement.getPosition();

      switch ( direction ) {

        case LEFT:
          return ( firstPosition.x < secondPosition.x ) ? firstElement : secondElement;
View Full Code Here

        if ( ! perimeterPipe.isColored() ) {
          coloredFace = false;
          break;
        }

        Junction vertex = this.levelGraph.getEdgeSource( perimeterPipe );
        if ( ! vertex.isColored() ) {
          coloredFace = false;
          break;
        }

        vertex = this.levelGraph.getEdgeTarget( perimeterPipe );

        if ( ! vertex.isColored() ) {
          coloredFace = false;
          break;
        }
      }
View Full Code Here

    this.faces = new HashMap<>( facesMap.size() );

    for (Map.Entry<Set<Pipe>, Integer> faceAndId : facesMap.entrySet()) {
      /* Per ogni faccia ... */
      Pipe firstPipe = faceAndId.getKey().iterator().next();
      Junction lastJunction = levelMap.getEdgeSource( firstPipe );
      Pipe lastPipe = null;
      GeneralPath faceShape = new GeneralPath();
      faceShape.moveTo( lastJunction.getPosition().x, lastJunction.getPosition().y );
      while ( ! firstPipe.equals( lastPipe ) ) {
        /* Aggiunge la linea*/

        Pipe nextPipe = null;
        final Set<Pipe> connectedSegments = new HashSet<>( levelMap.edgesOf( lastJunction ) );
        if ( lastPipe == null ) {
          /* È il primo loop */
          lastPipe = firstPipe;
        }

        /* Scarta il segmento già percorso */
        connectedSegments.remove( lastPipe );

        for (Pipe perimeterSegment : faceAndId.getKey()) {
          /* Tra tutti i segmenti del perimetro seleziona solo quello che confina con il vertice corrente */
          if ( connectedSegments.contains( perimeterSegment ) ) {
            nextPipe = perimeterSegment;
            break;
          }
        }


        if ( nextPipe == null ) {
          if( THROW_EXCEPTION_ON_FACES_ERROR ) {
            throw new IllegalArgumentException("Invalid faces set");
          } else {
            lastPipe = firstPipe;
            faceShape.closePath();
          }
        } else {

          lastPipe = nextPipe;

          final Junction edgeSource = levelMap.getEdgeSource( nextPipe );
          lastJunction = edgeSource.equals( lastJunction ) ? levelMap
              .getEdgeTarget( nextPipe ) : edgeSource;

          final Point junctionPosition = lastJunction.getPosition();
          faceShape.lineTo( junctionPosition.x, junctionPosition.y );
        }
View Full Code Here

      faces = new HashMap<>( facesMap.size() );

      for (Map.Entry<Set<Pipe>, Integer> faceAndId : facesMap.entrySet()) {
      /* Per ogni faccia ... */
        Pipe firstPipe = faceAndId.getKey().iterator().next();
        Junction lastJunction = levelMap.getEdgeSource( firstPipe );
        Pipe lastPipe = null;
        GeneralPath faceShape = new GeneralPath();
        faceShape.moveTo( lastJunction.getPosition().x, lastJunction.getPosition().y );
        while ( ! firstPipe.equals( lastPipe ) ) {
        /* Aggiunge la linea*/

          Pipe nextPipe = null;
          final Set<Pipe> connectedSegments = new HashSet<>( levelMap.edgesOf( lastJunction ) );
          if ( lastPipe == null ) {
          /* È il primo loop */
            lastPipe = firstPipe;
          }

        /* Scarta il segmento già percorso */
          connectedSegments.remove( lastPipe );

          for (Pipe perimeterSegment : faceAndId.getKey()) {
          /* Tra tutti i segmenti del perimetro seleziona solo quello che confina con il vertice corrente */
            if ( connectedSegments.contains( perimeterSegment ) ) {
              nextPipe = perimeterSegment;
              break;
            }
          }


          if ( nextPipe == null ) {
            throw new IllegalArgumentException();
          }

          lastPipe = nextPipe;

          final Junction edgeSource = levelMap.getEdgeSource( nextPipe );
          lastJunction = edgeSource.equals( lastJunction ) ? levelMap.getEdgeTarget( nextPipe ) : edgeSource;

          final Point junctionPosition = lastJunction.getPosition();
          faceShape.lineTo( junctionPosition.x, junctionPosition.y );
        }
        faceShape.closePath();
View Full Code Here

TOP

Related Classes of org.gbcpainter.game.model.grid.Junction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.