Package org.gbcpainter.geom

Examples of org.gbcpainter.geom.Segment


      /* JUNCTION */
      final Point elementPosition = ( (Junction) element ).getPosition();
      final Set<Pipe> connectedEdges = graph.edgesOf( (Junction) element );
      assert ! connectedEdges.isEmpty();
      for (final Pipe edge : connectedEdges) {
        Segment geomEdge = edge.getSegment();
        Point otherPoint = geomEdge.getA();
        if ( otherPoint.equals( elementPosition ) ) {
          otherPoint = geomEdge.getB();
        }

        boolean isCandidate = false;
        switch ( direction ) {
          case LEFT:
View Full Code Here


        int secondFace = lineParsingRawData[5];

        this.lineGraph.addVertex( first );
        this.lineGraph.addVertex( second );

        Segment createdSegment = this.lineGraph.addEdge( first, second );

        Set<Segment> faceSet;
        /*
          If firstFace or secondFace are EXTERNAL_FACE_PIPE_ID,
            this pipe is an external pipe.
View Full Code Here

    boolean error = false;
    this.faces = new HashMap<>( this.facesMap.size() );
    try {
      for (Map.Entry<Set<Segment>, Integer> faceAndId : this.facesMap.entrySet()) {
        /* Per ogni faccia ... */
        Segment firstPipe = faceAndId.getKey().iterator().next();
        Point lastJunction = levelMap.getEdgeSource( firstPipe );
        Segment lastPipe = null;
        GeneralPath faceShape = new GeneralPath();
        faceShape.moveTo( lastJunction.x, lastJunction.y );
        while ( ! firstPipe.equals( lastPipe ) ) {
        /* Aggiunge la linea*/

          Segment nextPipe = null;
          final Collection<Segment> connectedSegments = new HashSet<>(
              this.levelMap.edgesOf(lastJunction ) );
          if ( lastPipe == null ) {
          /* È il primo loop */
            lastPipe = firstPipe;
View Full Code Here

      If the segment was not touched by the cursor return null,
      else return the walked part
     */
    for (Map.Entry<ImmutableSegment2D, PERPENDICULAR_DIRECTION> part : this.segmentsList.entrySet()) {

      final Segment actualSegment = part.getKey();
      final PERPENDICULAR_DIRECTION direction = part.getValue();

      if ( actualSegment.equals( originalSegment ) ) {
        /*
          direction segment is a segment that may be longer than the parameter segment,
          see walkSegment for details.

          We need to intersect it with the parameter segment
View Full Code Here

    if ( this.isTerminated() ) {
      throw new TerminatedAnimationException();
    }

    double movementLength = this.getMovementLength( millisTime );
    Segment resultPart = null;
    //Iterate the path and return the path segment the cursor is over
    for (Map.Entry<ImmutableSegment2D, PERPENDICULAR_DIRECTION> part : this.segmentsList.entrySet()) {

      final Segment actualSegment = part.getKey();
      final PERPENDICULAR_DIRECTION direction = part.getValue();
      resultPart = actualSegment;

      movementLength -= getLength( actualSegment, direction );
      if ( movementLength <= 0.0 ) {
View Full Code Here

    double movementLength = this.getMovementLength( millisTime );
    Point2D resultPoint = null;
    //Iterate over the path and return the actual position
    for (Map.Entry<ImmutableSegment2D, PERPENDICULAR_DIRECTION> part : this.segmentsList.entrySet()) {

      final Segment actualSegment = part.getKey();
      final PERPENDICULAR_DIRECTION direction = part.getValue();

      movementLength -= getLength( actualSegment, direction );

      if ( movementLength <= 0.0 ) {
View Full Code Here

     */
    while ( iterator.hasNext() ) {
      final Map.Entry<ImmutableSegment2D, PERPENDICULAR_DIRECTION> part = iterator.next();

      final Segment actualSegment = part.getKey();
      final PERPENDICULAR_DIRECTION direction = part.getValue();

      if ( contains( actualSegment.getLine2D(), anyPathPoint ) ) {
        if ( ! isVertex( actualSegment.getLine2D(), anyPathPoint ) ) {
          return getPercentageOfNonStartPoint( actualSegment, direction, movementLength, anyPathPoint );
        } else {
          final double beforeLineChange = Math.min( getPercentageOfNonStartPoint( actualSegment, direction, movementLength, anyPathPoint ), 0.5 );
          if ( beforeLineChange == 0.5 ) {
            movementLength -= getLength( actualSegment, direction );
            if ( iterator.hasNext() ) {
              final Map.Entry<ImmutableSegment2D, PERPENDICULAR_DIRECTION> nextEntry = iterator.next();

              final Segment nextSegment = nextEntry.getKey();
              final PERPENDICULAR_DIRECTION nextSegmentDirection = nextEntry.getValue();

              final double afterLineChange = getPercentageOfStartPoint( nextSegment, nextSegmentDirection, movementLength, anyPathPoint );
              return afterLineChange + beforeLineChange;
            } else {
View Full Code Here

  @NotNull
  @Override
  public PERPENDICULAR_DIRECTION getBeforeDirection( @NotNull final Point anyPathPoint ) throws IllegalArgumentException {
    for (Map.Entry<ImmutableSegment2D, PERPENDICULAR_DIRECTION> part : this.segmentsList.entrySet()) {
      final Segment actualSegment = part.getKey();
      final PERPENDICULAR_DIRECTION direction = part.getValue();
      if ( contains( actualSegment.getLine2D(), anyPathPoint ) ) {
        return direction;
      }
    }
    throw new IllegalArgumentException("Point not in the path (" + anyPathPoint + ")");
  }
View Full Code Here

       return the segment direction. If it is an extremity of a segment, return the
       direction of the next segment or null if it is the end of path point.
     */
    while ( iterator.hasNext() ) {
      final Map.Entry<ImmutableSegment2D, PERPENDICULAR_DIRECTION> part = iterator.next();
      final Segment actualSegment = part.getKey();
      final PERPENDICULAR_DIRECTION direction = part.getValue();

      if ( contains( actualSegment.getLine2D(), anyPathPoint ) ) {
        if ( isVertex( actualSegment.getLine2D(), anyPathPoint ) ) {
          if ( iterator.hasNext() ) {
            //Not the end of the path
            return iterator.next().getValue();
          } else {
            //The end of the path, no 'next' direction
View Full Code Here

      return;
    }

    final Iterable<PipePart> parts = new TreeSet<>( this.colorParts );
    final TextureLoader loader = GraphicsEnv.getInstance().getTextureLoader();
    final Segment pipeSegment = this.getSegment();

    final Dimension textureDimension;

    int gamePosition;
    final int upperLimit;

    /*
      Stampa le texure su schermo.

      Game position mantiene la posizione matematica della tubatura (model), e andrà dall'ascissa dell'estremo
      più a sinistra se la tubatura è orizzontale oppure dall'ordinata dell'estremo superiore se verticale.
      Upperlimit è impostato al limite opposto.

      Viene prima dipinta la parte non colorata, poi la parte colorata.

      screenPosition mantiene la posizione che deve avere la texture su schermo.

      screenPosition viene aggiornato a ogni pezzo di texture come un cursore.

      Questa parte riguarda il disegno delle sole parti non modificate in questo step.
     */
    Rectangle screenRect;
    Point screenPosition;
    final Iterator<Map.Entry<Integer, Boolean>> changedIterator = this.changedParts.entrySet()
                                                                               .iterator();
    Map.Entry<Integer, Boolean> nextSkip = changedIterator.hasNext() ? changedIterator.next() : null;

    if ( this.isVertical() ) {
      textureDimension = loader.getDimension( NON_COLORED_PART_VERTICAL );
      gamePosition = pipeSegment.getMinY();
      upperLimit = pipeSegment.getMaxY();

      for (final PipePart part : parts) {

        for (; gamePosition <= upperLimit && gamePosition < part.getStart(); gamePosition++) {
          screenRect = GraphicsEnv.getInstance().gamePointAndTextureToScreen( new Point( pipeSegment.getXA(), gamePosition ), textureDimension );
          screenPosition = new Point( screenRect.x, screenRect.y );
          final String pickTexture;

          if ( nextSkip != null && nextSkip.getKey() == gamePosition ) {
            pickTexture = ( nextSkip.getValue() ) ? COLORED_PART_VERTICAL : NON_COLORED_PART_VERTICAL;
            nextSkip = changedIterator.hasNext() ? changedIterator.next() : null;
          } else {
            pickTexture = NON_COLORED_PART_VERTICAL;
          }

          this.doDraw( g2, pickTexture, screenPosition );
        }

        for (; gamePosition <= part.getEnd(); gamePosition++) {
          screenRect = GraphicsEnv.getInstance().gamePointAndTextureToScreen( new Point( pipeSegment.getXA(), gamePosition ), textureDimension );
          screenPosition = new Point( screenRect.x, screenRect.y );
          final String pickTexture;

          if ( nextSkip != null && nextSkip.getKey() == gamePosition ) {
            pickTexture = ( nextSkip.getValue() ) ? COLORED_PART_VERTICAL : NON_COLORED_PART_VERTICAL;
            nextSkip = changedIterator.hasNext() ? changedIterator.next() : null;
          } else {
            pickTexture = COLORED_PART_VERTICAL;
          }

          this.doDraw( g2, pickTexture, screenPosition );
        }

      }

      for (; gamePosition <= upperLimit; gamePosition++) {
        screenRect = GraphicsEnv.getInstance().gamePointAndTextureToScreen( new Point( pipeSegment.getXA(), gamePosition ), textureDimension );
        screenPosition = new Point( screenRect.x, screenRect.y );
        final String pickTexture;

        if ( nextSkip != null && nextSkip.getKey() == gamePosition ) {
          pickTexture = ( nextSkip.getValue() ) ? COLORED_PART_VERTICAL : NON_COLORED_PART_VERTICAL;
          nextSkip = changedIterator.hasNext() ? changedIterator.next() : null;
        } else {
          pickTexture = NON_COLORED_PART_VERTICAL;
        }

        this.doDraw( g2, pickTexture, screenPosition );
      }

    } else {
      textureDimension = loader.getDimension( NON_COLORED_PART_HORIZONTAL );

      gamePosition = pipeSegment.getMinX();
      upperLimit = pipeSegment.getMaxX();

      for (final PipePart part : parts) {

        for (; gamePosition <= upperLimit && gamePosition < part.getStart(); gamePosition++) {
          screenRect = GraphicsEnv.getInstance().gamePointAndTextureToScreen( new Point( gamePosition, pipeSegment.getYA() ), textureDimension );
          screenPosition = new Point( screenRect.x, screenRect.y );
          final String pickTexture;

          if ( nextSkip != null && nextSkip.getKey() == gamePosition ) {
            pickTexture = ( nextSkip.getValue() ) ? COLORED_PART_HORIZONTAL : NON_COLORED_PART_HORIZONTAL;
            nextSkip = changedIterator.hasNext() ? changedIterator.next() : null;
          } else {
            pickTexture = NON_COLORED_PART_HORIZONTAL;
          }
          this.doDraw( g2, pickTexture, screenPosition );

        }

        for (; gamePosition <= part.getEnd(); gamePosition++) {

          screenRect = GraphicsEnv.getInstance().gamePointAndTextureToScreen( new Point( gamePosition, pipeSegment.getYA() ), textureDimension );
          screenPosition = new Point( screenRect.x, screenRect.y );
          final String pickTexture;

          if ( nextSkip != null && nextSkip.getKey() == gamePosition ) {
            pickTexture = ( nextSkip.getValue() ) ? COLORED_PART_HORIZONTAL : NON_COLORED_PART_HORIZONTAL;
            nextSkip = changedIterator.hasNext() ? changedIterator.next() : null;
          } else {
            pickTexture = COLORED_PART_HORIZONTAL;
          }
          this.doDraw( g2, pickTexture, screenPosition );
        }
      }

      for (; gamePosition <= upperLimit; gamePosition++) {

        screenRect = GraphicsEnv.getInstance().gamePointAndTextureToScreen( new Point( gamePosition, pipeSegment.getYA() ), textureDimension );
        screenPosition = new Point( screenRect.x, screenRect.y );
        final String pickTexture;

        if ( nextSkip != null && nextSkip.getKey() == gamePosition ) {
          pickTexture = ( nextSkip.getValue() ) ? COLORED_PART_HORIZONTAL : NON_COLORED_PART_HORIZONTAL;
View Full Code Here

TOP

Related Classes of org.gbcpainter.geom.Segment

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.