⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slope.java

📁 BOOK:Beginning Algorithms Code Examples
💻 JAVA
字号:
package com.wrox.algorithms.geometry;/** * Represents the slope of a {@link Line}. * Objects of this class are immutable. */public class Slope {    private final double _rise;    private final double _travel;    public Slope(double rise, double travel) {        _rise = rise;        _travel = travel;    }    public boolean isVertical() {        return _travel == 0;    }    public int hashCode() {        return (int) (_rise * _travel);    }    public boolean equals(Object object) {        if (this == object) {            return true;        }        if (object == null || object.getClass() != getClass()) {            return false;        }        Slope other = (Slope) object;        if (isVertical() && other.isVertical()) {            return true;        }        if (isVertical() || other.isVertical()) {            return false;        }        return (asDouble()) == (other.asDouble());    }    public double asDouble() {        if (isVertical()) {            throw new IllegalStateException("Vertical slope cannot be represented as double");        }        return _rise / _travel;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -