Debian Codegraph @

src/com/github/weisj/jsvg/geometry/SVGLine.java

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
•1 /*
2 * MIT License
3 *
4 * Copyright (c) 2021-2025 Jannis Weis
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
7 * associated documentation files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in all copies or
13 * substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
16 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 *
21 */
22 package com.github.weisj.jsvg.geometry;
23
24 import java.awt.*;
25 import java.awt.geom.Line2D;
26 import java.awt.geom.Rectangle2D;
27
28 import org.jetbrains.annotations.NotNull;
29
30 import com.github.weisj.jsvg.attributes.value.LengthValue;
31 import com.github.weisj.jsvg.geometry.util.GeometryUtil;
32 import com.github.weisj.jsvg.renderer.MeasureContext;
33 import com.github.weisj.jsvg.renderer.RenderContext;
34
35 public final class SVGLine implements SVGShape {
36
37 private final @NotNull Line2D.Float line = new Line2D.Float();
38 private final LengthValue x1;
39 private final LengthValue y1;
40 private final LengthValue x2;
41 private final LengthValue y2;
42
43 public SVGLine(@NotNull LengthValue x1, @NotNull LengthValue y1, @NotNull LengthValue x2, @NotNull LengthValue y2) {
44 this.x1 = x1;
45 this.y1 = y1;
46 this.x2 = x2;
47 this.y2 = y2;
48 }
49
50 @Override
51 public boolean canBeFilled() {
52 return false;
53 }
54
55 private void validateShape(@NotNull MeasureContext measureContext) {
56 line.setLine(
57 x1.resolve(measureContext), y1.resolve(measureContext),
58 x2.resolve(measureContext), y2.resolve(measureContext));
59 }
60
61 @Override
62 public @NotNull Shape shape(@NotNull RenderContext context, boolean validate) {
63 if (validate) validateShape(context.measureContext());
64 return line;
65 }
66
67 @Override
68 public @NotNull Rectangle2D bounds(@NotNull RenderContext context, boolean validate) {
69 if (validate) validateShape(context.measureContext());
70 return line.getBounds2D();
71 }
72
73 @Override
74 public double pathLength(@NotNull RenderContext context) {
75 MeasureContext measureContext = context.measureContext();
76 return GeometryUtil.lineLength(
77 x1.resolve(measureContext), y1.resolve(measureContext),
78 x2.resolve(measureContext), y2.resolve(measureContext));
79 }
80
81 @Override
82 public boolean isClosed(@NotNull RenderContext context) {
83 return false;
84 }
85 }