1 /*
   2  * Copyright (c) 2012, 2014, Oracle and/or its affiliates.
   3  * All rights reserved. Use is subject to license terms.
   4  *
   5  * This file is available and licensed under the following license:
   6  *
   7  * Redistribution and use in source and binary forms, with or without
   8  * modification, are permitted provided that the following conditions
   9  * are met:
  10  *
  11  *  - Redistributions of source code must retain the above copyright
  12  *    notice, this list of conditions and the following disclaimer.
  13  *  - Redistributions in binary form must reproduce the above copyright
  14  *    notice, this list of conditions and the following disclaimer in
  15  *    the documentation and/or other materials provided with the distribution.
  16  *  - Neither the name of Oracle Corporation nor the names of its
  17  *    contributors may be used to endorse or promote products derived
  18  *    from this software without specific prior written permission.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31  */
  32 
  33 package com.oracle.javafx.scenebuilder.kit.editor.panel.content.guides;
  34 
  35 /**
  36  *
  37  */
  38 class HorizontalSegment extends AbstractSegment {
  39 
  40     private final double x1;
  41     private final double x2;
  42     private final double y;
  43     private final double length;
  44 
  45     public HorizontalSegment(double x1, double x2, double y) {
  46         this.x1 = x1;
  47         this.x2 = x2;
  48         this.y = y;
  49         this.length = Math.abs(x2 - x1);
  50     }
  51 
  52     /*
  53      * AbstractSegment
  54      */
  55 
  56     @Override
  57     public double getX1() {
  58         return x1;
  59     }
  60 
  61     @Override
  62     public double getX2() {
  63         return x2;
  64     }
  65 
  66     @Override
  67     public double getY1() {
  68         return y;
  69     }
  70 
  71     @Override
  72     public double getY2() {
  73         return y;
  74     }
  75 
  76     @Override
  77     public double getLength() {
  78         return length;
  79     }
  80 
  81     /*
  82      * Object
  83      */
  84     @Override
  85     public int hashCode() {
  86         int hash = 7;
  87         hash = 89 * hash + (int) (Double.doubleToLongBits(this.x1) ^ (Double.doubleToLongBits(this.x1) >>> 32));
  88         hash = 89 * hash + (int) (Double.doubleToLongBits(this.x2) ^ (Double.doubleToLongBits(this.x2) >>> 32));
  89         hash = 89 * hash + (int) (Double.doubleToLongBits(this.y) ^ (Double.doubleToLongBits(this.y) >>> 32));
  90         return hash;
  91     }
  92 
  93     @Override
  94     public boolean equals(Object obj) {
  95         if (obj == null) {
  96             return false;
  97         }
  98         if (getClass() != obj.getClass()) {
  99             return false;
 100         }
 101         final HorizontalSegment other = (HorizontalSegment) obj;
 102         if (Double.doubleToLongBits(this.x1) != Double.doubleToLongBits(other.x1)) {
 103             return false;
 104         }
 105         if (Double.doubleToLongBits(this.x2) != Double.doubleToLongBits(other.x2)) {
 106             return false;
 107         }
 108         if (Double.doubleToLongBits(this.y) != Double.doubleToLongBits(other.y)) {
 109             return false;
 110         }
 111         return true;
 112     }
 113 
 114 
 115     /*
 116      * Comparable
 117      */
 118     @Override
 119     public int compareTo(AbstractSegment o) {
 120         assert o != null;
 121         return Double.compare(this.length, o.getLength());
 122     }
 123 }