栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用PathIterator返回约束一个Area的所有线段?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用PathIterator返回约束一个Area的所有线段?

这是可行的(我相信在所有情况下),但可能需要进行更彻底的测试:

Area area; // The value is set elsewhere in the pre    ArrayList<double[]> areaPoints = new ArrayList<double[]>();ArrayList<Line2D.Double> areaSegments = new ArrayList<Line2D.Double>();double[] coords = new double[6];for (PathIterator pi = area.getPathIterator(null); !pi.isDone(); pi.next()) {    // The type will be SEG_LINETO, SEG_MOVETO, or SEG_CLOSE    // Because the Area is composed of straight lines    int type = pi.currentSegment(coords);    // We record a double array of {segment type, x coord, y coord}    double[] pathIteratorCoords = {type, coords[0], coords[1]};    areaPoints.add(pathIteratorCoords);}double[] start = new double[3]; // To record where each polygon startsfor (int i = 0; i < areaPoints.size(); i++) {    // If we're not on the last point, return a line from this point to the next    double[] currentElement = areaPoints.get(i);    // We need a default value in case we've reached the end of the ArrayList    double[] nextElement = {-1, -1, -1};    if (i < areaPoints.size() - 1) {        nextElement = areaPoints.get(i + 1);    }    // Make the lines    if (currentElement[0] == PathIterator.SEG_MOVETO) {        start = currentElement; // Record where the polygon started to close it later    }    if (nextElement[0] == PathIterator.SEG_LINETO) {        areaSegments.add(     new Line2D.Double(         currentElement[1], currentElement[2],         nextElement[1], nextElement[2]     ) );    } else if (nextElement[0] == PathIterator.SEG_CLOSE) {        areaSegments.add(     new Line2D.Double(         currentElement[1], currentElement[2],         start[1], start[2]     ) );    }}// areaSegments now contains all the line segments


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/453907.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号